code ... ⁄code
HTML5 code element
The code element allows you to mark up computer code. »video
About code
- is an optional element
- multiple code elements allowed per HTML5 document
Display & support code
- display in browser »video
- display type: inline





Parents, children code
- code nested within elements »code parents
- elements nested within code »code children
»examples
Attributes code
- required: none
- optional: global attributes, event attributes
Observation: class global attribute on code element allows you to specify the language the piece of code belongs to:
e.g. for JavaScript:
<code class="language-javascript"> ... <⁄code>
Syntax code
1 | <> ... </> »video |
Attributes and Values code (comma separated)
< | attribute | = | "attribute_value(s)" | > | Video | Examples |
---|---|---|---|---|---|---|
1. specific attributes | ||||||
All Specific Attributes | ||||||
2. global attributes | ||||||
1. | accesskey | = | keyboard key | »img | <accesskey="h"> ... </ > | |
2. | class | = | class name | »html »img | <class="class_name"> ... </ > | |
3. | contenteditable | = | "", , true, false | »html | <contenteditable="true"> ... </ > | |
4. | contextmenu | = | menu id value | »html | <contextmenu="menu_id_value"> ... </ > | |
5. | data-* | = | value | - | <data-http-error="404"> ... </ > | |
6. | dir | = | ltr, rtl, auto | »html | <dir="ltr"> ... </ > | |
7. | draggable | = | true, , false | »img | <draggable="false"> ... </ > | |
8. | dropzone | = | copy, move, link, string:, file: | - | <dropzone="copy"> ... </ > | |
9. | hidden | = | "", , hidden | »html »img | <hidden="hidden"> ... </ > | |
10. | id | = | id name | »html »img | <id="unique_id_name"> ... </ > | |
11. | itemid | = | URL | - | - | |
12. | itemprop | = | string | »link »a | - | |
13. | itemref | = | string | - | - | |
14. | itemscope | = | "", , itemscope | - | - | |
15. | itemtype | = | absolute URL | - | - | |
16. | lang | = | language code | »html »head»title »img | <lang="en"> ... </ > | |
17. | spellcheck | = | "", , true, false | »html | <spellcheck="true"> ... </ > | |
18. | style | = | CSS property:value | »html »img | <style="color:red"> ... </ > | |
19. | tabindex | = | integer | »img | <tabindex="3"> ... </ > | |
20. | title | = | text | »html »link»style »abbr»dfn »img »meter | <title="html page"> ... </ > | |
21. | translate | = | "", yes, no | »html »img | <translate="yes"> ... </ > | |
All Global Attributes | ||||||
3. global event attributes | ||||||
1. | onclick | = | script | » list | <element onclick="script" > ... | |
2. | ondblclick | = | script | » list | <element ondblclick="script" > ... | |
All Event Attributes |
Video demonstration code element
HTML5 code element: mark up computer code
min | video details |
---|---|
00:00 | video tutorial: code element |
00:05 | code element allows you to mark computer code |
00:11 | 'reverse()', 'Array' and the fragment of code are part of the JavaScript language, language that can be specified like this, if you want: example on 'reverse()' <code class="language-javascript"> reverse() <⁄code> the language is added through class attribute like this: class="language-" |
00:19 | since the next: ('reverse()', 'Array' and the fragment of code) are part of the programming language (JavaScript), are considered computer code → we can mark them properly using code element |
00:50 | you can recognize the computer code from the rest of the content due to its monospace font |
00:55 | for this fragment of JavaScript code, we can have in browser the exact same display ⁄format as in our Notepad file IF we use the pre element which preformats a block of text |