Slide 1
Advanced HTML for Good Developers
Slide 2
HTML IS SIMPLE & VERY FRIENDLY.
BATMANDY
Slide 3
WE MAKE THE MISTAKE OF ASSUMING BECAUSE IT’S SIMPLE IT’S NOT VALUABLE BATMANDY
Slide 4
THERE ARE ~115 USABLE* HTML ELEMENTS
BATMANDY
Slide 5
<p> <a> <button> <li> <script> <main> <link> <form> <img> <ul> <div> <section> <input> <h2> <label> <span> <h1> <article> BATMANDY
Slide 6
<p> <a> <button> <li> <script> <main> <link> <form> <img> <ul> <div> <section> <input> <h2> <label> <span> <h1> <article> BATMANDY
Slide 7
Slide 8
Slide 9
<html> … <body> <header> <h1>Some text</h1> </header> <p>A paragraph…</p> <ul> <li>A list item</li> <li>Another item</li> </ul> <p>More content…</p> <hr> ….
BATMANDY
Slide 10
THE DOM TREE IS CONSTRUCTED OFF WHAT WE PROVIDE.
BATMANDY
Slide 11
Slide 12
interface dog { name: string age: number isFluffy: boolean }
BATMANDY
Slide 13
WE DETERMINE WHAT WE EXPECT THE CONTENT TO BE
BATMANDY
Slide 14
<html> <body> <header> <h1>Dogs: They are good</h1> </header> <main> <h2>Why are dogs good?</h2> <p>All dogs are good, they are the goodest doggies.</p> <figure> <img href=”dog.png” alt=”A white golden retriever, with his head dropping to the side and tongue dangling out of his mouth” /> <figcaption>Michaelangelo AKA “Jello”</figcaption> </figure> </main> </body> </html>
BATMANDY
Slide 15
interface dog { name: any age: any isFluffy: any }
BATMANDY
Slide 16
<html> <body> <div> <div>Dogs: They are good</div> </div> <div> <div>Why are dogs good?</div> <div>All dogs are good, they are the goodest doggies.</div> <div> <img href=”dog.png” alt=”A golden retriever” /> <div>Michaelangelo AKA “Jello”</div> </div> </div> </body> </html> BATMANDY
Slide 17
IF YOU CHOOSE A GENERIC ELEMENT YOU GET A GENERIC OUTPUT BATMANDY
Slide 18
Slide 19
Slide 20
NOT EVERYONE INTERACTS THE SAME BATMANDY
Slide 21
ACCESSIBILITY TREE
BATMANDY
Slide 22
Slide 23
Slide 24
Slide 25
Slide 26
Slide 27
Slide 28
Using HTML correctly is just UX for assistive tech & other technologies. @BATMANDY BATMANDY
Slide 29
Slide 30
Eric Bailey
PERFORMANCE & THE ACCESSIBILITY TREE Check out Eric’s presentation on Notist! noti.st/ericwbailey
BATMANDY
Slide 31
Advanced HTML for Good Developers
Slide 32
GOOGLE RECOMMENDS Less than 1,500 nodes Max depth of 32 nodes No parent node with more than 60 child nodes BATMANDY
Slide 33
Slide 34
DON’T JUST USE DIVS
BATMANDY
Slide 35
<p> <a> <button> <li> <script> <main> <link> <form> <img> <ul> <div> <section> <input> <h2> <label> <span> <h1> <article> BATMANDY
Slide 36
USE THE NAMED ELEMENT FOR WHAT YOU ARE BUILDING BATMANDY
Slide 37
If you have a header, use the <header> element <header>This is a header</header>
BATMANDY
Slide 38
HTML is intentionally simple, elements are named to help you out. BATMANDY
Slide 39
Use heading elements in the correct order <h1> <h2> <h3> <h4> <h5> <h6> BATMANDY
Slide 40
Slide 41
Good Developers
HTML and it’s Bene ts
H1
fi
BATMANDY
Slide 42
<h3>Good Developers</h3> <h1>HTML and it’s Benefits</h1> <div>Good Developers</div> <h1>HTML and it’s Benefits</h1> <span>Good Developers</span> <h1>HTML and it’s Benefits</h1>
BATMANDY
Slide 43
<h1> <span>Good Developers</span> HTML and it’s Benefits </h1>
BATMANDY
Slide 44
<h1>Good Developers</h1> <h2>HTML and it’s Benefits</h2>
BATMANDY
Slide 45
JUST BECAUSE IT’S IN A DESIGN DOES NOT MEAN YOU HAVE TO DO IT. BATMANDY
Slide 46
ALWAYS CONSIDER THE CONTEXT BATMANDY
Slide 47
Slide 48
Inputs & Dates <label for=“myDate“>Date:</label> <input type=”date” id=”myDate” name=“awesome-date” value=”2023-10-07” />
BATMANDY
Slide 49
USE THE NAMED ELEMENT FOR WHAT YOU ARE BUILDING BATMANDY
Slide 50
USE THE NAMED O M
O T S
T F
T E H
E IM
YOU ARE BUILDING BATMANDY
Slide 51
DISCOVERABLE vs KNOWN DATES BATMANDY
Slide 52
MAYBE YOU DON’T NEED A DATEPICKER https://adrianroselli.com/2019/07/maybe-you-dont-need-a-date-picker.html BATMANDY
Slide 53
MAKE THE MOST OF BUILT-IN FUNCTIONALITY BATMANDY
Slide 54
<div onclick=”doSomething();”> I am a button </div>
BATMANDY
Slide 55
<div tabindex=”0” role=”button” aria-pressed=“button” onclick=”doSomething();”> I am a button </div> const ENTER = 13; const SPACE = 32; myButton.addEventListener(‘keydown’, function(event) { if (event.keyCode === ENTER || event.keyCode === SPACE) { event.preventDefault(); doSomething(event); } }); function toggleButton(button) { button.setAttribute(“aria-pressed”, button.getAttribute(“aria-pressed”) === “true” ? “false” : “true” )}; } function doSomething() { // Your actual code to do what you want )};
BATMANDY
Slide 56
If you need a button, use the <button> element <button>This is a button</button>
BATMANDY
Slide 57
FEATURES
<div>
<button>
Clickable / Tapable Focusable Keyboard Interaction Announce via assistive tech Submit / Reset Forms Disabled attribute Reported to accessibility tree :active, :hover, :focus & :disabled states BATMANDY
Slide 58
A Button CSS Reset
By Andy Bell
button { display: inline-block; border: none; margin: 0; padding: 0; font-family: sans-serif; font-size: 1rem; line-height: 1; background: transparent; -webkit-appearance: none; }
BATMANDY
Slide 59
<div tabindex=”0” role=”button” aria-pressed=“button” onclick=”doSomething();”> I am a button </div> const ENTER = 13; const SPACE = 32; myButton.addEventListener(‘keydown’, function(event) { if (event.keyCode === ENTER || event.keyCode === SPACE) { event.preventDefault(); doSomething(event); } }); function toggleButton(button) { button.setAttribute(“aria-pressed”, button.getAttribute(“aria-pressed”) === “true” ? “false” : “true” )}; } function doSomething() { // Your actual code to do what you want )};
BATMANDY
Slide 60
A Button CSS Reset
By Andy Bell
button { display: inline-block; border: none; margin: 0; padding: 0; font-family: sans-serif; font-size: 1rem; line-height: 1; background: transparent; -webkit-appearance: none; }
BATMANDY
Slide 61
If you need a link, use the <a> element FEATURES
<div>
<a>
Navigate to a page or view Change url Browser redraw/refresh Focusable Keyboard Interaction Open in new window Reported to accessibility tree :active, :hover, :focus, :link & :visited states
BATMANDY
Slide 62
A <a> navigates to a new url, whereas a <button> triggers or toggles something in an interface?
BATMANDY
Slide 63
IT’S LIKE USING A PRE-INSTALLED JS LIBRARY. BATMANDY
Slide 64
DON’T FORGET ABOUT THE ATTRIBUTES BATMANDY
Slide 65
ARIA ATTRIBUTES FILL THE GAPS IN STANDARD HTML TO GIVE MORE CONTEXT TO THE ACCESSIBILITY TREE BATMANDY
Slide 66
aria-pressed aria-selected aria-expanded aria-grabbed aria-live aria-hidden aria-labelledby
https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Attributes
BATMANDY
Slide 67
“
If you’re writing CSS that conveys information. Ask yourself is that information also in the accessibility tree? If not, a bit of ARIA might help. JULIE GRUNDY
” BATMANDY
Slide 68
accept ATTRIBUTE rel=“” accept pattern spellcheck contenteditable
BATMANDY
Slide 69
pattern ATTRIBUTE rel=“” accept pattern
<input pattern=”\d{4,4}” title=”4 digits”>
spellcheck contenteditable
BATMANDY
Slide 70
contenteditable ATTRIBUTE rel=“” accept pattern
<p contenteditable>content</p>
spellcheck contenteditable
BATMANDY
Slide 71
spellcheck ATTRIBUTE rel=“” accept pattern
<p contenteditable spellcheck=”true”>
spellcheck contenteditable
BATMANDY
Slide 72
rel ATTRIBUTE rel=“” accept pattern spellcheck contenteditable
BATMANDY
Slide 73
LOADING & PERFORMANCE
BATMANDY
Slide 74
PRELOADING OFF SCREEN IMAGES G N DI
AK
A O L Y Z A L A
BATMANDY
Slide 75
Slide 76
Native lazy-loading for the web <img src=”img.png” loading=”lazy” /> <picture> <source media=”(min-width: 800px)” … /> <img src=“img.png” loading=“lazy” /> </picture> <iframe src=“img.png” loading=“lazy” />
Slide 77
Only lazy load images that are not in viewport BATMANDY
Slide 78
LARGEST CONTENTFUL PAINT
(LCP)
: the render time of the largest image or text block visible within the viewport when the page rst starts loading.
fi
BATMANDY
Slide 79
Only lazy load images that are not in viewport BATMANDY
Slide 80
Lazy load distance threshold is based on the type of resource and the connection type BATMANDY
Slide 81
Optimising loading <img src=”img.png” loading=”lazy” width=”200” height=“200” fetchpriority=“high” />
BATMANDY
Slide 82
Fetch Priority high: You want the browser to prioritize it low:
You want the browser to deprioritize it
auto: You want the browser to decide
(Default)
BATMANDY
Slide 83
fetchpriority sets the relative priority BATMANDY
Slide 84
Fetch Priority <ul class=“carousel”> <li><img src=”img/1.jpg” <li><img src=”img/2.jpg” <li><img src=”img/3.jpg” <li><img src=”img/4.jpg” </ul>
fetchpriority=”high”></li> fetchpriority=”low”></li> fetchpriority=”low”></li> fetchpriority=”low”></li>
BATMANDY
Slide 85
Fetch Priority <ul class=“my-unecessary-carousel“> <li><img src=”img/1.jpg” fetchpriority=”high”></li> <li><img src=”img/2.jpg” fetchpriority=”low” loading=”lazy”></li> <li><img src=”img/3.jpg” fetchpriority=”low” loading=”lazy”></li> <li><img src=”img/4.jpg” fetchpriority=”low” loading=”lazy”></li> </ul>
BATMANDY
Slide 86
Fetch Priority
Assign fetchpriority to <iframe> elements Used in JavaScript fetch to prioritize API calls Prioritise resource tags like <script> & <link>
BATMANDY
Slide 87
Be more explicit with Resource Hints
BATMANDY
Slide 88
RESOURCE HINTS
<link rel=”preconnect” href=“https://gooddogs.com/img”> <link rel=”dns-prefetch” href=“https://gooddogs.com/img”>
BATMANDY
Slide 89
RESOURCE HINTS
<link rel=”preconnect” href=”….”> Starts the connection process as soon as possible
BATMANDY
Slide 90
RESOURCE HINTS
<link rel=”preconnect” href=”….”> Starts the connection process as soon as possible Only for critical connections
BATMANDY
Slide 91
RESOURCE HINTS
<link rel=”dns-prefetch” href=”….”> Starts the DNS lookup
https://caniuse.com/?search=dns-prefetch
BATMANDY
Slide 92
Slide 93
DON’T JUST USE DIVS USE THE NAMED ELEMENTS LEVERAGE BUILT-IN FUNCTIONALITY EXPLORE THE ATTRIBUTES CONVEY INFORMATION & CONTEXT BATMANDY
Slide 94
MAKE IT USEFUL MAKE IT USABLE
BATMANDY
Slide 95
HTML IS NOT JUST THE FOUNDATION WE BUILD ON. IT’S VITAL IN MAKING OUR WEBSITES ACCESSIBLE . USABLE & PERFORMANT BATMANDY
Slide 96
HTML IS A HACK FOR MAKING GOOD WEBSITES & APPS BATMANDY
Slide 97
THANKS BURNT TOAST CREATIVE @burnttoastcre8v
BATMANDY
Slide 98
THANKS & RESOURCES Julie Grundy - @stringyland.bsky.social Eric Bailey - @social.ericwbailey.website/@eric ‣developer.mozilla.org/docs/Web/HTML ‣https://web.dev/iframe-lazy-loading/ ‣noti.st/ericwbailey/Yfyaxa/the-intersection-of-performance-and-accessibility ‣developers.google.com/web/tools/lighthouse/audits/dom-size ‣medium.com/@mandy.michael/understanding-why-semantic-html-is-important-as-told-by-typescriptbd71ad41e6c4 ‣https://web.dev/fetch-priority/ ‣https://www.smashingmagazine.com/2022/04/boost-resource-loading-new-priority-hint-fetchpriority/ ‣https://adrianroselli.com/2019/07/maybe-you-dont-need-a-date-picker.html ‣https://source.chromium.org/chromium/chromium/src/+/main:third_party/blink/renderer/core/frame/ settings.json5;l=963-995 ‣https://web.dev/lcp/ ‣https://addyosmani.com/blog/lazy-loading/ ‣https://www.debugbear.com/blog/resource-hints-rel-preload-prefetch-preconnect BATMANDY