Internet
Fact-checked

At EasyTechJunkie, we're committed to delivering accurate, trustworthy information. Our expert-authored content is rigorously fact-checked and sourced from credible authorities. Discover how we uphold the highest standards in providing you with reliable knowledge.

Learn more...

What is an HTML Code Tag?

Victoria Blackburn
Victoria Blackburn

All HTML documents are made up of text only. These documents include both the text to be displayed and instructions on how it should be displayed by the Internet browser. The instructions are given by the tags that are included in the text document. The HTML code tag is one such instruction, and it identifies text as computer code.

When using most tags, it is necessary to include an opening and closing tag so the browser knows where to use the instructions. The code tag is one of the tags that must have an opening and closing tag. When the it is used, it takes the following format: <code>hello</code>. If this instruction were read by the browser, it would change how the word hello is formatted so that it is differentiated from other text on the page. Usually, when the code tag is used, a browser changes the font of the words surrounded by the tags to monospace, or a font similar to that.

HTML code tags identifies text as computer code.
HTML code tags identifies text as computer code.

This tag doesn’t have any specific attributes, or characteristics, that are unique. When writing an HTML document, the format of any computer code takes can be specified by using other general attributes. If style sheets are being used for formatting the document, id, class and style can be used to point to how the text is styled. Other attributes that can be included with the code tag are title, lang and dir title gives a specific title to the tag, lang specifies the language, and dir gives the direction of the text, from left to right or right to left.

Code tags provide the basic information for how text, borders, images and other page elements will be displayed.
Code tags provide the basic information for how text, borders, images and other page elements will be displayed.

Events are actions taken by a web user, such as clicking or double clicking something on the page. These events can be coded for within the HTML document and can also be included within the code tag. Optional events that can be used as attributes for the code tag include onclick, ondblclick, onkeydown, onkeypress, onkeyup, onmousedown, onmouseup, onmouseover and onmouseout.

Most browsers have a default style to use when the code tag is encountered within an HTML document. Using attributes with this tag is completely optional, so none have to be specified. If the attributes are not included, the browser will just use the default setting. It is important to note that not all browsers will display code text in the same way. The browsers will display the code text differently than the surrounding text of the page, but each browser may not format the code text in the same way if attributes and styles are not included within the code tag.

Discuss this Article

Post your comments
Login:
Forgot password?
Register:
    • HTML code tags identifies text as computer code.
      By: alexeysmirnov
      HTML code tags identifies text as computer code.
    • Code tags provide the basic information for how text, borders, images and other page elements will be displayed.
      By: Stephen VanHorn
      Code tags provide the basic information for how text, borders, images and other page elements will be displayed.