codegurukool.com · Free coding tutorials & online compiler

Home › HTML Tutorial › All commands

All commands

Every command of this course: name, detailed description, syntax and example code.

Every command used in this course, with its name, a detailed description, the syntax and an example.

h1

Definition: Defines the main heading of the page. Use one per page.

Syntax:

<h1>Heading text</h1>

Example:

<h1>Welcome</h1>

p

Definition: Defines a paragraph of text.

Syntax:

<p>Text</p>

Example:

<p>Hello, web!</p>

a

Definition: Creates a hyperlink to another page or resource.

Syntax:

<a href="URL">link text</a>

Example:

<a href="https://example.com">Visit</a>

href

Definition: Attribute of a that sets where the link goes.

Syntax:

<a href="URL">text</a>

Example:

<a href="https://example.com">Go</a>

img

Definition: Embeds an image in the page.

Syntax:

<img src="file" alt="description">

Example:

<img src="x.png" alt="A sleeping cat">

alt

Definition: Text description of an image, shown if it fails to load and read by screen readers.

Syntax:

<img src="file" alt="text">

Example:

<img src="x.png" alt="A sleeping cat">

ul

Definition: Unordered (bulleted) list. Items go inside li.

Syntax:

<ul><li>item</li></ul>

Example:

<ul><li>Apples</li><li>Pears</li></ul>

ol

Definition: Ordered (numbered) list.

Syntax:

<ol><li>item</li></ol>

Example:

<ol><li>Mix</li><li>Bake</li></ol>

table

Definition: Shows data in rows (tr) and cells (td, th).

Syntax:

<table><tr><th>head</th></tr><tr><td>cell</td></tr></table>

Example:

<table border="1"><tr><th>Name</th><th>Age</th></tr><tr><td>Asha</td><td>20</td></tr></table>

input

Definition: Form control where the user types or chooses a value.

Syntax:

<input type="text" name="n">

Example:

<input type="text" placeholder="Your name">

label

Definition: Caption tied to a form control. Clicking it focuses the field.

Syntax:

<label for="id">Text</label>

Example:

<label for="n">Name</label> <input id="n">

required

Definition: Attribute that forces a field to be filled before submit.

Syntax:

<input required>

Example:

<form><input required><button>Send</button></form>

h2

Definition: Use h1 for the main title and h2 to h6 for sub-sections.

Syntax:

h2

Example:

<h2>Section</h2>

↗ Headings and paragraphs

header

Definition: Tags like header , nav , main , article , section and footer help screen readers and search engines understand your page.

Syntax:

header

Example:

<style>header,footer{background:#14213d;color:#fff;padding:8px}nav a{margin-right:10px}</style>
<header><h2>My Site</h2></header>

↗ Semantic layout

nav

Definition: Tags like header , nav , main , article , section and footer help screen readers and search engines understand your page.

Syntax:

nav

Example:

<style>header,footer{background:#14213d;color:#fff;padding:8px}nav a{margin-right:10px}</style>
<nav><a href="#">Home</a><a href="#">About</a></nav>

↗ Semantic layout

main

Definition: Tags like header , nav , main , article , section and footer help screen readers and search engines understand your page.

Syntax:

main

Example:

<main><article><h3>Post title</h3><p>Post text.</p></article></main>

↗ Semantic layout

article

Definition: Tags like header , nav , main , article , section and footer help screen readers and search engines understand your page.

Syntax:

article

Example:

<main><article><h3>Post title</h3><p>Post text.</p></article></main>

↗ Semantic layout

footer

Definition: Tags like header , nav , main , article , section and footer help screen readers and search engines understand your page.

Syntax:

footer

Example:

<style>header,footer{background:#14213d;color:#fff;padding:8px}nav a{margin-right:10px}</style>
<footer>2026</footer>

↗ Semantic layout

id

Definition: An id must be unique on a page.

Syntax:

id

Example:

<p id="main" title="Hover me">Unique paragraph</p>

↗ Classes, ids and attributes

class

Definition: A class can be shared by many elements, and is how you target groups for CSS and JavaScript.

Syntax:

class

Example:

<p class="note">Note one</p>
<p class="note">Note two</p>

↗ Classes, ids and attributes

title

Definition: title shows a tooltip.

Syntax:

title

Example:

<p id="main" title="Hover me">Unique paragraph</p>

↗ Classes, ids and attributes

audio

Definition: Use audio and video with the controls attribute and a src file.

Syntax:

audio

Example:

<audio controls src="your-sound.mp3"></audio>

↗ Audio and video

video

Definition: Use audio and video with the controls attribute and a src file.

Syntax:

video

Example:

<video controls width="280" src="your-video.mp4">
Your browser does not support video.
</video>

↗ Audio and video

controls

Definition: Use audio and video with the controls attribute and a src file.

Syntax:

controls

Example:

<audio controls src="your-sound.mp3"></audio>
<video controls width="280" src="your-video.mp4">

↗ Audio and video

src

Definition: Use audio and video with the controls attribute and a src file.

Syntax:

src

Example:

<audio controls src="your-sound.mp3"></audio>
<video controls width="280" src="your-video.mp4">

↗ Audio and video

date

Definition: Types like date , number , range and color give people native pickers, and validate on mobile keyboards too.

Syntax:

date

Example:

<p><label>Date <input type="date"></label></p>

↗ Input types

number

Definition: Types like date , number , range and color give people native pickers, and validate on mobile keyboards too.

Syntax:

number

Example:

<p><label>Age <input type="number" min="1" max="99"></label></p>

↗ Input types

range

Definition: Types like date , number , range and color give people native pickers, and validate on mobile keyboards too.

Syntax:

range

Example:

<p><label>Volume <input type="range"></label></p>

↗ Input types

color

Definition: Types like date , number , range and color give people native pickers, and validate on mobile keyboards too.

Syntax:

color

Example:

<p><label>Color <input type="color"></label></p>

↗ Input types

lang

Definition: Always declare <!DOCTYPE html> and lang , write lowercase tags, give images alt text, use one h1 , and close every element.

Syntax:

lang

Example:

<html lang="en">

↗ HTML best practices

index.html

Definition: Save the file as index.html and open it in a browser.

Syntax:

index.html

Example:

<p>Save as index.html, then open it.</p>'

↗ HTML editors

html

Definition: <!DOCTYPE html> declares HTML5.

Syntax:

html

Example:

<!DOCTYPE html>
<html>
</html>'

↗ HTML basic

head

Definition: html wraps the page, head holds information about it, and body holds what people see.

Syntax:

head

Example:

<head><title>Skeleton</title></head>

↗ HTML basic

body

Definition: html wraps the page, head holds information about it, and body holds what people see.

Syntax:

body

Example:

<body><p>Visible content</p></body>

↗ HTML basic

br

Definition: Some elements are empty ( br , hr , img ) and have no closing tag.

Syntax:

br

Example:

Line one<br>Line two'

↗ HTML elements

hr

Definition: Some elements are empty ( br , hr , img ) and have no closing tag.

Syntax:

hr

Example:

<hr>

↗ HTML elements

style

Definition: The style attribute takes CSS declarations.

Syntax:

style

Example:

<p style='color:tomato;font-size:24px;background:#eee'>Styled inline</p>'

↗ HTML styles

strong

Definition: Use strong and em for meaning, and mark , small , del , ins , sub , sup for the rest.

Syntax:

strong

Example:

<p><strong>Important</strong>, <em>stressed</em>, <mark>marked</mark>, <small>small</small>, <del>old</del> <ins>new</ins>, H<sub>2</sub>O, x<sup>2</sup></p>'

↗ HTML formatting

em

Definition: Use strong and em for meaning, and mark , small , del , ins , sub , sup for the rest.

Syntax:

em

Example:

<p><strong>Important</strong>, <em>stressed</em>, <mark>marked</mark>, <small>small</small>, <del>old</del> <ins>new</ins>, H<sub>2</sub>O, x<sup>2</sup></p>'

↗ HTML formatting

mark

Definition: Use strong and em for meaning, and mark , small , del , ins , sub , sup for the rest.

Syntax:

mark

Example:

<p><strong>Important</strong>, <em>stressed</em>, <mark>marked</mark>, <small>small</small>, <del>old</del> <ins>new</ins>, H<sub>2</sub>O, x<sup>2</sup></p>'

↗ HTML formatting

small

Definition: Use strong and em for meaning, and mark , small , del , ins , sub , sup for the rest.

Syntax:

small

Example:

<p><strong>Important</strong>, <em>stressed</em>, <mark>marked</mark>, <small>small</small>, <del>old</del> <ins>new</ins>, H<sub>2</sub>O, x<sup>2</sup></p>'

↗ HTML formatting

del

Definition: Use strong and em for meaning, and mark , small , del , ins , sub , sup for the rest.

Syntax:

del

Example:

<p><strong>Important</strong>, <em>stressed</em>, <mark>marked</mark>, <small>small</small>, <del>old</del> <ins>new</ins>, H<sub>2</sub>O, x<sup>2</sup></p>'

↗ HTML formatting

ins

Definition: Use strong and em for meaning, and mark , small , del , ins , sub , sup for the rest.

Syntax:

ins

Example:

<p><strong>Important</strong>, <em>stressed</em>, <mark>marked</mark>, <small>small</small>, <del>old</del> <ins>new</ins>, H<sub>2</sub>O, x<sup>2</sup></p>'

↗ HTML formatting

sub

Definition: Use strong and em for meaning, and mark , small , del , ins , sub , sup for the rest.

Syntax:

sub

Example:

<p><strong>Important</strong>, <em>stressed</em>, <mark>marked</mark>, <small>small</small>, <del>old</del> <ins>new</ins>, H<sub>2</sub>O, x<sup>2</sup></p>'

↗ HTML formatting

sup

Definition: Use strong and em for meaning, and mark , small , del , ins , sub , sup for the rest.

Syntax:

sup

Example:

<p><strong>Important</strong>, <em>stressed</em>, <mark>marked</mark>, <small>small</small>, <del>old</del> <ins>new</ins>, H<sub>2</sub>O, x<sup>2</sup></p>'

↗ HTML formatting

blockquote

Definition: blockquote is a long quote, q a short inline one, cite a work title and abbr an abbreviation.

Syntax:

blockquote

Example:

<blockquote cite='https://example.com'>A long quotation sits in its own block.</blockquote>

↗ Quotations and citations

q

Definition: blockquote is a long quote, q a short inline one, cite a work title and abbr an abbreviation.

Syntax:

q

Example:

<p>She said <q>hello</q> in <cite>My Book</cite>. <abbr title='HyperText Markup Language'>HTML</abbr></p>'

↗ Quotations and citations

cite

Definition: blockquote is a long quote, q a short inline one, cite a work title and abbr an abbreviation.

Syntax:

cite

Example:

<blockquote cite='https://example.com'>A long quotation sits in its own block.</blockquote>
<p>She said <q>hello</q> in <cite>My Book</cite>. <abbr title='HyperText Markup Language'>HTML</abbr></p>'

↗ Quotations and citations

abbr

Definition: blockquote is a long quote, q a short inline one, cite a work title and abbr an abbreviation.

Syntax:

abbr

Example:

<p>She said <q>hello</q> in <cite>My Book</cite>. <abbr title='HyperText Markup Language'>HTML</abbr></p>'

↗ Quotations and citations

rgb()

Definition: Set colors with names, #rrggbb , rgb() , hsl() and add transparency with rgba() .

Syntax:

rgb()

Example:

<p style='background:rgb(27,153,139)'>RGB</p>

↗ HTML colors

hsl()

Definition: Set colors with names, #rrggbb , rgb() , hsl() and add transparency with rgba() .

Syntax:

hsl()

Example:

<p style='background:hsl(45,100%,60%)'>HSL</p>

↗ HTML colors

rgba()

Definition: Set colors with names, #rrggbb , rgb() , hsl() and add transparency with rgba() .

Syntax:

rgba()

Example:

<p style='background:rgba(0,0,0,.2)'>RGBA</p>'

↗ HTML colors

link

Definition: Inline (style attribute), internal (a style element in the head) and external (a link to a .css file).

Syntax:

link

Example:

<!-- External: <link rel='stylesheet' href='style.css'> -->'

↗ CSS in HTML

width

Definition: Use src , alt , width and height .

Syntax:

width

Example:

<img alt='Green square' width='100' height='100' src='data:image/svg+xml,%3Csvg xmlns=%27http://www.w3.org/2000/svg%27 width=%27100%27 height=%27100%27%3E%3Crect width=%27100%27 height=%27100%27 fill=%27%231b998b%27/%3E%3C/svg%3E'>'

↗ HTML images

height

Definition: Use src , alt , width and height .

Syntax:

height

Example:

<img alt='Green square' width='100' height='100' src='data:image/svg+xml,%3Csvg xmlns=%27http://www.w3.org/2000/svg%27 width=%27100%27 height=%27100%27%3E%3Crect width=%27100%27 height=%27100%27 fill=%27%231b998b%27/%3E%3C/svg%3E'>'

↗ HTML images

tr

Definition: tr is a row, th a header cell and td a data cell.

Syntax:

tr

Example:

<thead><tr><th>Item</th><th colspan='2'>Price</th></tr></thead>
<tbody><tr><td>Pen</td><td>2</td><td>USD</td></tr></tbody>

↗ HTML tables

th

Definition: tr is a row, th a header cell and td a data cell.

Syntax:

th

Example:

<style>td,th{border:1px solid #888;padding:6px}table{border-collapse:collapse}</style>
<thead><tr><th>Item</th><th colspan='2'>Price</th></tr></thead>

↗ HTML tables

td

Definition: tr is a row, th a header cell and td a data cell.

Syntax:

td

Example:

<style>td,th{border:1px solid #888;padding:6px}table{border-collapse:collapse}</style>
<tbody><tr><td>Pen</td><td>2</td><td>USD</td></tr></tbody>

↗ HTML tables

thead

Definition: Use thead , tbody , colspan and rowspan for structure.

Syntax:

thead

Example:

<thead><tr><th>Item</th><th colspan='2'>Price</th></tr></thead>

↗ HTML tables

tbody

Definition: Use thead , tbody , colspan and rowspan for structure.

Syntax:

tbody

Example:

<tbody><tr><td>Pen</td><td>2</td><td>USD</td></tr></tbody>

↗ HTML tables

colspan

Definition: Use thead , tbody , colspan and rowspan for structure.

Syntax:

colspan

Example:

<thead><tr><th>Item</th><th colspan='2'>Price</th></tr></thead>

↗ HTML tables

div

Definition: Block elements ( div , p , h1 ) start a new line and fill the width.

Syntax:

div

Example:

<div style='background:#cde'>Block div</div>

↗ Block, inline and div

span

Definition: Inline elements ( span , a ) sit within text.

Syntax:

span

Example:

<p>Text with <span style='color:red'>an inline span</span>.</p>'

↗ Block, inline and div

button

Definition: Use button for actions.

Syntax:

button

Example:

<button type='button' onclick='alert(1)'>Click me</button>
<button disabled>Disabled</button>'

↗ HTML buttons

type

Definition: Set type to button , submit or reset .

Syntax:

type

Example:

<button type='button' onclick='alert(1)'>Click me</button>

↗ HTML buttons

iframe

Definition: An iframe shows another document inside your page.

Syntax:

iframe

Example:

<iframe src='about:blank' title='Empty frame' width='300' height='120' style='border:2px solid #888'></iframe>'

↗ HTML iframes

script

Definition: Put code in a script element, or load a file with src .

Syntax:

script

Example:

<script>document.getElementById('x').textContent='After';</script>'

↗ JavaScript in HTML

meta

Definition: The head can hold title , meta , link , style and script .

Syntax:

meta

Example:

<meta charset='utf-8'>
<meta name='viewport' content='width=device-width, initial-scale=1'>
<meta name='description' content='Free tutorials'>

↗ HTML head and meta

code

Definition: code for code, kbd for keyboard input, samp for output, var for variables and pre keeps spacing.

Syntax:

code

Example:

<pre><code>function hi() {
}</code></pre>'

↗ Computer code elements

kbd

Definition: code for code, kbd for keyboard input, samp for output, var for variables and pre keeps spacing.

Syntax:

kbd

Example:

<p>Press <kbd>Ctrl</kbd>+<kbd>S</kbd>. Output: <samp>Saved</samp>. Set <var>x</var> to 5.</p>

↗ Computer code elements

samp

Definition: code for code, kbd for keyboard input, samp for output, var for variables and pre keeps spacing.

Syntax:

samp

Example:

<p>Press <kbd>Ctrl</kbd>+<kbd>S</kbd>. Output: <samp>Saved</samp>. Set <var>x</var> to 5.</p>

↗ Computer code elements

var

Definition: code for code, kbd for keyboard input, samp for output, var for variables and pre keeps spacing.

Syntax:

var

Example:

<p>Press <kbd>Ctrl</kbd>+<kbd>S</kbd>. Output: <samp>Saved</samp>. Set <var>x</var> to 5.</p>

↗ Computer code elements

pre

Definition: code for code, kbd for keyboard input, samp for output, var for variables and pre keeps spacing.

Syntax:

pre

Example:

<pre><code>function hi() {
}</code></pre>'

↗ Computer code elements

action

Definition: action is the URL, method is get or post, target chooses where the response opens, autocomplete and novalidate adjust browser help.

Syntax:

action

Example:

<form action='/submit' method='post' autocomplete='off'>

↗ Form attributes

method

Definition: action is the URL, method is get or post, target chooses where the response opens, autocomplete and novalidate adjust browser help.

Syntax:

method

Example:

<form action='/submit' method='post' autocomplete='off'>

↗ Form attributes

autocomplete

Definition: action is the URL, method is get or post, target chooses where the response opens, autocomplete and novalidate adjust browser help.

Syntax:

autocomplete

Example:

<form action='/submit' method='post' autocomplete='off'>

↗ Form attributes

datalist

Definition: Use select , datalist , textarea , fieldset with legend , and output to build full forms.

Syntax:

datalist

Example:

<datalist id='l'><option>HTML</option><option>CSS</option></datalist><br>

↗ Form elements

textarea

Definition: Use select , datalist , textarea , fieldset with legend , and output to build full forms.

Syntax:

textarea

Example:

<textarea rows='3' cols='24'>Bio</textarea>

↗ Form elements

fieldset

Definition: Use select , datalist , textarea , fieldset with legend , and output to build full forms.

Syntax:

fieldset

Example:

<fieldset><legend>Profile</legend>
</fieldset>'

↗ Form elements

legend

Definition: Use select , datalist , textarea , fieldset with legend , and output to build full forms.

Syntax:

legend

Example:

<fieldset><legend>Profile</legend>

↗ Form elements

canvas

Definition: The canvas element is a bitmap you paint with the 2D context: shapes, text and images.

Syntax:

canvas

Example:

<canvas id='c' width='260' height='120' style='border:1px solid #888'></canvas>

↗ HTML canvas

VIDEO_ID

Definition: Replace VIDEO_ID with a real ID.

Syntax:

VIDEO_ID

Example:

<iframe width='280' height='160' src='https://www.youtube.com/embed/VIDEO_ID' title='Video' allowfullscreen></iframe>'

↗ HTML YouTube

draggable

Definition: Set draggable , then handle dragstart , dragover (call preventDefault ) and drop .

Syntax:

draggable

Example:

<div id='d' draggable='true'>Drag me</div><div id='z'>Drop here</div>

↗ Drag and drop API

preventDefault

Definition: Set draggable , then handle dragstart , dragover (call preventDefault ) and drop .

Syntax:

preventDefault

Example:

z.ondragover=e=>e.preventDefault();
z.ondrop=e=>{e.preventDefault();z.appendChild(d)};

↗ Drag and drop API

popover

Definition: Give an element the popover attribute and point a button at it with popovertarget .

Syntax:

popover

Example:

<button popovertarget='p'>Toggle popover</button>
<div id='p' popover style='padding:16px'>Hello from a popover.</div>'

↗ Popover API

popovertarget

Definition: Give an element the popover attribute and point a button at it with popovertarget .

Syntax:

popovertarget

Example:

<button popovertarget='p'>Toggle popover</button>

↗ Popover API

localStorage

Definition: localStorage persists, sessionStorage lasts until the tab closes.

Syntax:

localStorage

Example:

try{localStorage.setItem('n','Ada');o.textContent='Saved: '+localStorage.getItem('n')}

↗ Web storage API

postMessage

Definition: A worker runs a script in the background and talks to the page with postMessage , so the page stays responsive.

Syntax:

postMessage

Example:

const b=new Blob(['onmessage=e=>{let s=0;for(let i=0;i<=e.data;i++)s+=i;postMessage(s)}']);
w.postMessage(1e7);

↗ Web workers API

EventSource

Definition: EventSource keeps a connection open so a server can push messages.

Syntax:

EventSource

Example:

const s=new EventSource('/updates');

↗ Server-sent events API

Example code

<!DOCTYPE html>
<html>
<body>
  <h1>My first page</h1>
  <p>Hello, web!</p>
</body>
</html>

Run this code in the online editor

← Welcome to the HTML courseHTML introduction →