HTML tips

details/summary tags

Details/Summary Adding <summary> and <details> tags allows to implement accordeon without using any script or CSS methods.
This way improves accessibility for keybords or screenreaders users and does not require html attributes like id or data-*
Default opened tab Use the same syntax but use <details open>.
<details>  
    <summary>Visible title</summary> 
    Text content displayed on click.
</details>

source: Building Accordions With the HTML5 Details Tag (No JavaScript Needed)

Video/Audio capture input

The capture attribute allows access to mobile device's microphone/camera.
Notice it won't access your computers microphone/camera.

<input type="file" id="soundFile" capture="user" accept="audio/*" />

<input type="file" id="videoFile" capture="environment" accept="video/*" />

Note: the user value will get the user-facing camera while the environment value will get the outward-facing.

The audio tag




<audio controls autoplay>
    <source src = "/html5/audio.ogg" type = "audio/ogg" />
    <source src = "/html5/audio.wav" type = "audio/wav" />
        Your browser does not support the audio element.
</audio>

Note: add the loop attribute to start over everytime track ends.
Same attributes works with the video tag.

Ordered lists notation/start

  1. Item 1
  2. Item 2
  3. Item 3
  1. Introduction
  2. First Principles
  3. Second Principles
  4. Third Principles
<ol type="A"> // or <ol type="I">
    <li>Item 1</li>
    <li>Item 2</li>
    <li>Item 3</li>
</ol>

Note: after 26 items, list will keep on going with AA., AB., ...

  1. Step 4
  2. Step 5
<ol start="4">
    <li>Step 4</li>
    <li>Step 5</li>
</ol>

Note: the start attribute only works with numbers.

Some useful inline tags

You can higlight text using the <mark>tag.

You can cross out text without any CSS rule using the <s> tag

Use the <abbr> tag with a title attribute to display the meaning of a word/abbr when the user hovers on it

The time tag

The time tag allows machines like search engines to read temporal values inside texts.
It takes the attribute datetime.

<time datetime="2018-09-28 19:00"> le 28 septembre</time>

The spellcheck attribute

When set to true, will automatically check for spelling while user edit the content.

<textarea spellcheck="true">This exampull will be checkd fur spellung.
Et ça machre ausis en frnaçais.</textarea>

The translate attribute

This attribute prevent browser to translate some content to keep it in its original language.

<p translate="no">Ne pas Traduire ce Paragraphe.</p>

The tabindex attribute

Allows to manage priority when user uses tab to navigate through the page.

<p tabindex="1">Allows to manage priority when user uses tab to navigate through the <a href ="#" tabindex="2">page</a>.</p>

Note: consider semantic first to optimize accessibility

The datalist tag

Similar to the select option, display is more subtle.

<label>Chose a car model: </label>
    <input list="cars" id="carsInput" />

    <datalist id="cars">
        <option value="BMW" />
        <option value="Bentley" />
        <option value="Mercedes" />
        <option value="Audi" />
        <option value="Volkswagen" />
    </datalistm>

<button onclick="datalistcall()" type="button">Click Here</button>

The canvas tag

Create a zone you can fill with shapes/sketches or use as a free drawing space.

<canvas id="canvas" width="400" height="100" style="border:2px solid;">
//script:
var canvas = document.getElementById("canvas");
var ctx = canvas.getContext("2d");

// red rectangle:
ctx.fillStyle = "#FF0000";
ctx.fillRect(100, 20, 80, 80);

// blue rectangle:
ctx.fillStyle = "rgba(0, 0, 200, 0.8)";
ctx.fillRect(60, 70, 50, 100);

// circle:
ctx.fillStyle = "#FFFFFF";
ctx.arc(300, 75, 50, 0, 2 * Math.PI);
ctx.fill();

Vector Graphics

<svg id = "svgelem" height = "200" xmlns = "http://www.abc.org/2000/svg">
      <circle id = "redcircle" cx = "50" cy = "50" r = "50" fill = "red" />
 </svg>

<svg width="200" height="120">
  <rect x="20" y="10" rx="20" ry="20" width="140" height="90" style="fill:rgb(55, 208, 255);stroke:rgb(240, 230, 230);stroke-width:5;opacity:0.5" />
</svg>

Note: While canvas is rendered pixel by pixel, SVG is XML based and generate elements available whithin de DOM. Which means they can handle events.

The output tag

The empty output get updated with a result value generated by a script that execute a calculation.


Sum =
<form oninput="sumresult.value = parseInt(firstnum.value) + parseInt(secondnum.value)">
        <input type="number" name="firstnum" value="50" />
        <input type="number" name="secondnum" value="0" />
        <span>Sum = </span> <output name="sumresult"></output>
</form>

The progress tag

Loading:

The progress tag takes a value + a max value

<progress value="55" max="100"></progress>

This tag requires Javascript to update the value.

Hello
<button onClick="displayProgress()">Run Progress Bar</button>
<progress value="0" id="downloadProgress" max="30">Hello</progress>

<script>
let milisec=0
let max=30
function displayProgress(){

	if(milisec>=max){
	document.getElementById('message').innerHTML="Done!";
	}
	 
	milisec+=1;
	document.getElementById('downloadProgress').value=milisec;
	setTimeout("displayProgress()",max);
}
</script>

Source: HTML <progress> Tag

The meter tag

The meter tag allows to display static value.
Define min, max and a current value to generate a gauge.
Specify high, lowans optimum values update color content.

<meter id="score" min="0" max="100"
    low="30" high="66" optimum="80"
    value="50">
</meter>

Images mapping with area tags

Add a usemap attribute to the image you want to define clickable areas so you can add different links depending on where the user clicks.

Workplace Computer Phone Cup of coffee
<img src="workplace.jpg" alt="Workplace" usemap="#workmap" width="400" height="379">

<map name="workmap">
  <area shape="rect" coords="34,44,270,350" alt="Computer" href="https://en.wikipedia.org/wiki/Laptop">
  <area shape="rect" coords="290,172,333,250" alt="Phone" href="https://en.wikipedia.org/wiki/Smartphone">
  <area shape="circle" coords="337,300,44" alt="Cup of coffee" href="https://en.wikipedia.org/wiki/Coffee">
</map>

Note: area always works within a map tag and requires to define coordinates.

Open Graph meta tags

Launched by Facebook in 2010, Open Graph is a protocol that optimise web pages representation when they got shared on social networks.

<meta property="og:title" content="HTML Tips." />
<meta property="og:description" content="HTML Tips." />
<meta property="og:image" content="https://ahrefs.com/blog/wp-content/uploads/2019/12/fb-how-to-become-an-seo-expert.png" />

SOURCE: Open Graph: what you need to know.

More about OG: Open Graph Meta Tags: Everything You Need to Know.

Note: Twitter uses its own twitter:* properties for Twitter Cards (twitter doc).

Deprecated HTML features

A non exhaustive list of deprecated features in HTML5:

  • acronym
  • applet
  • basefont
  • big
  • center
  • dir
  • font
  • frame
  • frameset
  • isindex
  • noframes
  • noscript
  • s
  • strike
  • tt
  • u
  • SOURCE: [Medium | Faizan Khan] : "What’s new in HTML 5?"