HTML Tips and Best Practices
Pre tag
print preformatted text exactly like is written
Random
text
preformatted
Code tag
<code> code represent one line of code, multiples lines should be inside a <pre> tag
code {
background-color: #efefef;
padding:25px;
margin: 15px 0;
}
Use <em> and <strong>
Never use <b> and <i>, substitute to <strong> and <em>
Bold text and emphasize text
HTML Accordion
<details> element to create the accordion and <summary> as the accordion header
Just an accordion with basic HTML
Lorem ipsum dolor sit amet consectetur, adipisicing elit. Porro, commodi! Repudiandae deleniti repellat ipsa eum quo alias voluptas. Quisquam est iure praesentium totam enim alias voluptate cupiditate beatae optio aspernatur!
Highlight Text
<mark> to highlight the text
Lorem ipsum, dolor sit amet consectetur adipisicing elit.
Download
download attribute in links
<a href="path" download>
click herePhone, SMS and e-mail links
- Phone: href="tel:+phonenumber"
- SMS: href="sms:+phonenumber?body=message"
- E-mail: href="mailto:email@email.com?subject=subject&body=message"
Ordered List
start attribute start="number"
- Anakin Skywalker
- Luke Skywalker
- Darth Vader
- Obi-Wan Kenobi
File Upload Type
accept attribute in input type files
<input type="file" accept="image/*"> Only image types
Meter Element
No CSS or Javascript needed
Fieldset
group inputs and labels with fieldset
HTML Slider
<input type="range">
Your choice:
input search
The input type "search" have a clean button by default
Auto Complete
autocomplete attribute for phone assistance or autocomplete softwares
Noopener
Links with target="_blank" opens the link in a new tab. Without rel="noopener" the new tab can access your page via windows object
just an exampleLazy Loading
loading="lazy", load the image only when the user scrolls to them.
Image Caption
Use <figure> elemento to wrap the image and <figcaption> as caption
HTML Tag as plain text
Use "& lt ;" and "& gt ;" with no space
<p>Use "& lt ;" and "& gt " with no space</p>