Jump to content

Computer code element?


Yazidove

Recommended Posts

Some use fixed font size and spacing by default and show line breaks, so unlike what would normally happen without these tags they would become one continuous line of text code, it would show exactly as the layout of code you inserted in as.Also when inserting script tags etc. It would be just treated as text and not part of js code to run.Never actually used these but just pre tag.

Link to comment
Share on other sites

It is an inline element, and used primary to use a fixed font for the display of code, it is in the same groups of tags as <b> and <em> for use localy in text instead of having to style a span.

Link to comment
Share on other sites

They're all just semantic and don't necessarily do anything specific. It's to indicate to the entity that reads the HTML that what's between the tags is code.

 

I use the <code> element for code examples when writing documentation for my libraries. There's no need to wrap it in <pre> like the tutorial says, just use CSS to tell it how to deal with whitespace: http://www.w3schools.com/cssref/pr_text_white-space.asp

Link to comment
Share on other sites

I generally use code for small bits that are inline but for larger blocks I prefer to use pre because it default behavior is close enough to the way that I want code blocks to render that it does not take much CSS to do the presentation. I will also uses a readonly textarea for large blocks so I get the default scroll bars and don't have to set an overflow property to control the size of the rendered block.

 

I prefer the lazy approach of using tag defaults to reduce the amout of CSS I have to write.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...