Highlights
- Some of the best HTML tips and tricks for web developers are single attributes, not deep architectural fixes; most performance and accessibility audit flags trace back to an HTML attribute nobody set.
- fetchpriority, loading=”lazy”, decoding=”async”, and image width/height are the difference between a fast, stable page and one that fails Core Web Vitals.
- Native HTML elements like popover,
- Every tip on this list of HTML tips and tricks every web developer should know is a single attribute you can add today, with no new dependency and no sprint planning required.
Introduction
Ever run a Lighthouse audit expecting deep, scary problems and half the flags turn out to be image elements do not have explicit width and height or form elements do not have associated labels? No refactor needed. Just attributes nobody added.
That’s HTML for you. It’s the first language most of us learn, so we assume we’ve mastered it and stop paying attention. But it hasn’t stood still; browsers now handle things natively that used to mean pulling in a JS library: accordions, popups, form validation, smart image loading.
If you are at the same stage, thinking the same thing, below are the HTML attributes and elements that make the biggest difference for the least effort, the ones that actually show up in real Core Web Vitals reports and accessibility audits.
Also Read: Web Development Industry Statistics
20 Best HTML Tips & Tricks You Should Know
Twenty tips, all pulled from things that actually show up in real audits, not filler. Some fix performance, some fix accessibility, a few just save you from writing JavaScript you don’t need.
Worth reading start to finish; there’s a decent chance at least a couple of these are already quietly costing you somewhere in your codebase.
1. Keep Heading Levels in a Logical Sequence
It’s tempting to pick a heading tag based on how big the text looks on the page, but that’s the wrong way to think about it. A heading tag should describe what the content actually is, not what size you want it rendered at.
If you need an <h3> to look smaller than an <h2>, that’s a job for font-size in your CSS, not a reason to relabel the tag. Screen reader users navigate a page by jumping from heading to heading, the same way a sighted user skims a table of contents, so a broken outline breaks that shortcut for them.
Search engines lean on the same structure to figure out how your page is organized, as the Web Almanac’s accessibility chapter points out.
Before you touch an inherited codebase, it’s worth installing a heading-outline browser extension and just scrolling through the page. Ninety seconds of that will tell you more about a site’s real state than an hour spent reading its CSS.
Also Read: How to Organize the Content of Your Website?
2. Always Use Semantic HTML Where Possible
Here’s a good test to run on your own markup: if every style sheet on the site vanished right now, would the page still make sense?
Elements like <header>, <nav>, <main>, and <footer> become landmarks that assistive technology can jump between directly, instead of forcing a screen reader user to wade through the entire page.
Usage of <main> has climbed to 47% of pages according to the Web Almanac, which is progress, but it also means more than half the web still isn’t using it. Search crawlers and AI answer engines depend on this same structure to tell your actual content apart from navigation and boilerplate.
3. Hide Content with the hidden Attribute
If your stylesheet still has a .hidden { display: none; } class that someone added years ago, you can retire it. HTML already handles this natively:
There’s also a lesser-known value worth knowing about: hidden=”until-found” keeps content collapsed but still lets the browser’s built-in Ctrl+F search find it, which makes it a great fit for FAQ answers or long sections you want hidden but still discoverable.
One thing to keep in mind is that hidden is a hard display: none under the hood, so there’s nothing for a CSS transition to animate. If you want the reveal to be animated, toggle a class instead.
Also Read: 12 Problem-Solving Websites For Programmers
4. Make Content Editable with contenteditable
This single attribute turns any element into something a user can click into and type directly, without a textarea and without pulling in a rich-text library. It’s a solid fit for simple inline edits, comment boxes, and lightweight “edit in place” fields.
The one thing you have to be careful about is that you should never trust what comes out of it. Pasted content can carry formatting you never asked for, or in the worst case, a script tag someone is using to test your defenses. Sanitize it before it ever touches your database, the same way you would any other user input.
5. Prevent Translation of Brand Names with translate="no"
This attribute tells browser-based translation tools to leave a piece of text exactly as it is, which matters most for brand names that would otherwise get mangled into something unrecognizable.
It’s worth wrapping code snippets in it too, since auto-translated code tends to come out as complete nonsense once a translator starts rewriting variable names.
Also Read: Best AI Tools for Web Developers You Should Know
6. Prioritize Your Hero Image with fetchpriority
Browsers make a guess about which resources to load first, and sometimes that guess is wrong, especially for hero images loaded through CSS backgrounds or component frameworks. This attribute lets you override that guess directly.
Web.dev’s write-up on the Fetch Priority API documents real, measurable LCP improvements from applying it to the right element, but the key is applying it to only your actual LCP image. Mark every image on the page as high priority, and you’ve recreated the exact problem you were trying to solve.
7. Lazy-Load Offscreen Images
This attribute tells the browser to hold off on fetching an image until it’s about to enter the viewport, rather than downloading every image on the page the moment it’s parsed. Just make sure it doesn’t end up on your hero image, since a meaningful share of pages still make that exact mistake, which delays the one image that should be loading first.
A simple rule that holds up well in practice: anything visible without scrolling either loads normally or gets fetchpriority="high" if it’s your LCP element, and everything below the fold gets loading="lazy".
Also Read: Top 11 Best Code Editors & IDEs for Python
8. Specify Image Dimensions
Setting width and height tells the browser exactly how much space to reserve before the image has even downloaded, which prevents the layout jump that tanks your Cumulative Layout Shift (CLS) score. Most mobile pages still ship at least one image with no dimensions set, which the Web Almanac found to be the single most common cause of layout shift on the entire web.
Pair it with img { height: auto; } in your CSS so the image still scales responsively. The HTML attributes just set the aspect ratio the browser reserves; they don’t lock you into a fixed size.
Also Read: How to Get Images For Your eCommerce Website?
9. Serve Modern Image Formats with <picture>
AVIF and WebP compress noticeably smaller than JPEG or PNG at comparable visual quality, and <picture> is what lets you take advantage of that without gambling on browser support. List your <source> tags from most-preferred to least-preferred, since browsers grab the first format they understand and fall back to the plain <img> if nothing else matches.
10. Help Browsers Autofill Forms Correctly
This attribute tells the browser what kind of data a field expects, so it can offer to fill it in from information it already has saved. Get it wrong or skip it entirely, and users end up typing everything by hand on a phone keyboard, which is a genuine source of drop-off on any form longer than a few fields.
The WHATWG spec has the full list of recognized values, so there’s almost always an exact right answer rather than a guess.
It’s worth testing this on an actual phone before you ship it, not just on desktop Chrome. Mobile autofill behaves differently across iOS and Android, and a mismatched value is the kind of thing that slips through review because it looks perfectly fine on a laptop.
Also Read: Know the Difference Between CSS and CSS3
11. Add Autocomplete Suggestions with <datalist>
Unlike a <select> dropdown, <datalist> only suggests options; it doesn’t restrict what a user can type. That makes it a good fit for a field like city or country, where common answers show up as one-tap suggestions but someone typing something that isn’t on the list still gets to finish the form.
12. Create Popups with the popover Attribute
This attribute turns any element into a native overlay that renders above the rest of the page and can be dismissed by clicking outside it or hitting Escape, all without a line of JavaScript. As of 2026, it’s reached Baseline widely-available status across Chrome, Firefox, Safari, and Edge, so it’s genuinely production-safe.
There are three values worth knowing: auto is the default and closes when you click outside it, manual stays open until you explicitly close it, and hint is meant for tooltip-style content that shouldn’t interrupt anything else that’s open. If you need a real focus trap and an inert background, like a genuine confirmation modal, reach for <dialog> instead.
Also Read: Will AI Replace Web Developers
13. Improve Mobile Keyboards with inputmode
This attribute tells a mobile browser which virtual keyboard to bring up, whether that’s a numeric pad or an email-friendly layout with the @ symbol right there, instead of defaulting to the full alphabet keyboard on a field that was never going to need letters.
One mix-up worth avoiding: inputmode=”numeric” is not the same thing as type=”number”. Save type=”number” for values the browser should treat mathematically, like a quantity field with up and down arrows. For anything that looks numeric but isn’t actually a number, like a PIN or an OTP, use type="text" with inputmode=”numeric” instead; otherwise, you end up with strange increment arrows sitting on a PIN field.
Also Read: Best YouTube Channels For Learning Web Development
14. Customize Mobile Keyboard Actions with enterkeyhint
This attribute swaps the generic return-arrow icon on a mobile keyboard for a contextual label like “Search” or “Send,” depending on what pressing it will actually do. It’s easy to dismiss as cosmetic, but it’s the kind of detail users register subconsciously without being able to say why a form felt easier to fill out.
15. Build Accordions with <details> and <summary>
Before reaching for a JavaScript accordion component, it’s worth checking whether <details> and <summary> already do the job.
You get native open and close behavior with no click handlers or state management to write, and the content stays in the DOM the entire time, which means it’s still crawlable and still readable by a screen reader even while it’s visually collapsed. That makes this a particularly good fit for FAQ sections, which are also exactly the kind of content AI answer engines pull direct answers from.
Add the open attribute if you want a section expanded by default, and style the default triangle marker with the::marker pseudo-element instead of hiding it and rebuilding your own icon from scratch.
Also Read: Is Web Development Dying in Future?
16. Use Built-In HTML Validation Before Reaching for JavaScript
Before writing a validation function for something like “is this a valid email,” it’s worth checking whether HTML already covers it. Attributes like required, pattern, min, and max, along with typed inputs like email or url, catch a large share of common validation cases with zero JavaScript, and the browser applies invalid and valid CSS automatically.
This doesn’t replace server-side validation, and it never should, since you can’t trust the client alone. But it is a genuine first line of defense, and it cuts down on how much validation logic gets hand-rolled for things the browser was already going to check.
If the native error messages don’t match your brand, setCustomValidity() lets you override just the message text while keeping the built-in validation behavior underneath.
17. Improve Mobile Keyboards with inputmode
This attribute tells a mobile browser which virtual keyboard to bring up, whether that’s a numeric pad or an email-friendly layout with the @ symbol right there, instead of defaulting to the full alphabet keyboard on a field that was never going to need letters.
One mix-up worth avoiding: inputmode=”numeric” is not the same thing as type=”number”. Save type=” number” for values the browser should treat mathematically, like a quantity field with up and down arrows. For anything that looks numeric but isn’t actually a number, like a PIN or an OTP, use type="text" with inputmode=”numeric” instead; otherwise you end up with strange increment arrows sitting on a PIN field.
18. Customize Mobile Keyboard Actions with enterkeyhint
This attribute swaps the generic return-arrow icon on a mobile keyboard for a contextual label like “Search” or “Send,” depending on what pressing it will actually do. It’s easy to dismiss as cosmetic, but it’s the kind of detail users register subconsciously without being able to say why a form felt easier to fill out.
Also Read: Is Web Development Dying in Future?
19. Build Accordions with <details> and <summary>
Before reaching for a JavaScript accordion component, it’s worth checking whether <details> and <summary> already do the job. You get native open and close behavior with no click handlers or state management to write, and the content stays in the DOM the entire time, which means it’s still crawlable and still readable by a screen reader even while it’s visually collapsed.
That makes this a particularly good fit for FAQ sections, which are also exactly the kind of content AI answer engines pull direct answers from.
Also Read: Know What PHP is Used For in Web Development?
20. Use Built-In HTML Validation Before Reaching for JavaScript
Before writing a validation function for something like “is this a valid email,” check whether HTML already covers it. Attributes like required, pattern, min, and max, along with typed inputs like email or url, catch most common cases with zero JavaScript, and the browser applies: invalid and: valid CSS automatically.
This isn’t a replacement for server-side validation, just a solid first line of defense. If the native error messages don’t match your brand, setCustomValidity() lets you override the message text while keeping the built-in behavior underneath.
Conclusion
You don’t need to memorize this list. Bookmark it, and the next time you’re building a form, an image gallery, or a modal, come back and check what HTML already gives you before you reach for a package.
A lot of these attributes solve problems developers still solve with JavaScript out of habit, simply because that’s how it was done a few years ago, before the browser caught up.
The real takeaway here is a habit, not a checklist: before you write code to solve a problem, pause and ask if the browser already solves it.
More often than you’d expect, the answer is that it already handles it, and you get to ship less code, with fewer edge cases to maintain down the line.





