Skip to main content
View on YouTube to comment and like!

Syntax Video

We've been using headings wrong . . .

Chapter 1 0:00

Welcome

welcome to syntax on this Monday Hasty treat we're going to be talking about headings in HTML that's right H1 through H6 they might be the first element you learned but they are more interesting than many people give them credit and uh perhaps they're one of those things that a lot of people get wrong so we're going to be talking all about common issues that you might face we're going to be talking about dos and don'ts we're going to be talking about why you need good heading structure what the benefit is and then perhaps some tools to help you along there in some further reading my name is Scott tulinsky I'm a developer from Denver with me as always is West boss what's up Wes not too much just got done recording a really good one with uh Chris lner so I'm buzzing on that one that was awesome yeah I'm I'm straight up it's B movie over here I'm buing buzzing like crazy uh I'm feeling that that was a great episode you know if you want to be buzzing like the B Movie you

Chapter 2 0:57

Syntax Brought to you by Sentry

might want uh error handling in exception tracking in your application and for that you'll want to check out Sentry at sentry.io syntax and uh you can sign up for Sentry and you get all that good stuff in your application because this podcast is presented by Sentry all right let's get into it headings so we're going to be talking all about heading design in websites and how you do it but first and most important and we'll get into this in Greater detail after we learn some of the facts is why why do we even care about this stuff and the big reason is for for two things one accessibility headings are extremely important for screen readers specifically in accessibility uh keyboard navigation not as important but screen readers they really rely on the information in headings to allow users to easily navigate the site in a way that makes sense and without proper heading design and proper heading

Chapter 3 1:27

Why do we care about Headings?

hierarchy your users won't be able to navigate your website with a screen reader and that is a tremendous problem for many people who rely on that technology whether it is uh people who are visually impaired um people who who just rely on maybe people can't uh they have dyslexia they can't read as well and they need that maybe that auditory version of the website there's a lot of reasons here that this heading structure is important for accessibility tools and also SEO right robots they're scanning your website they need to know the hierarchy just as much as any other screen reading technology does right they need to know the hierarchy and the order and the structure of your website and headings really do act as landmarks for that outline that is your website right so let's get into thought process and design here and I think the thing here that you're going to take away from this episode more than anything else is

that heading design is all about providing a proper outline for your website and that's really the way to think about headings you should be thinking about them as it builds an outline for which the content will live in your site so when you're teacher in high school told you to start writing a paper you often times would say all right uh I I'm being told to start with an outline and the first thing you do is you open up Microsoft Word and you give that file a name that file name is your H1 okay the file name is your H1 what the thing is or the page title is your H1 maybe it's the cover sheet and it has a title that's the H1 then you start building out an outline so you do perhaps a heading introduction and then you tab over uh who and what is going on right and then perhaps You tab back and then you tab forward and then you tab forward and you build essentially a tabed in outline and that outline is

Chapter 4 2:58

Heading design provides an outline for your website

essentially your H1 through H6 system each time you you move over one space you are adding to your heading number and so therefore you can imagine that you're never going from H2 to H6 but people do that in web programming all the time because they're just not thinking about it they're thinking about maybe perhaps visual right this visual hierarchy of things and these headings don't really relate to that at all because in reality when you're designing that outline of your headings it should always match how you would if you were doing a legitimate outline so don't skip heading numbers number one that's a big do not do you wouldn't do that in outline uh if your outlining goes from like Notions does a dark circle to a outline Circle to a block you wouldn't go from the dark circle to the block you can't do that uh and just like with web you shouldn't be able to do that either it doesn't make any sense so that's the big big picture here it

should always match the outline of the content now here are common mistakes people make one of the big common mistakes people make is that they think about it visually all right I have this H2 it's nice and big it's perfect for this spot in the design I'm just going to do an H2 here uh and that's specifically not what you should be doing you should be using the correct indentation level of your hes to match the structure of the page at that given point so picking an H tag just because it's CSS that it's baked into the browser or perhaps the framework you're using matches the design is not the right idea and likewise don't just pick something because it's a bold version of the size you're currently using or any of that uh often times two people will omit a heading because they feel like the design shows that there's a heading there but if you omit the heading entirely screen rers and in robots in general they don't even see that section

as being anything they don't understand it doesn't build a landmark there for the screeners to be able to look off of if you think about like a doc for even just a JavaScript library often the documentation like in my own Shameless plug West boss.com for/ JavaScript my JavaScript guide the table of contents is literally generated from all the headings and if I were just willy-nilly throwing headings into random pieces then I wouldn't be able to generate that nice table of content so I think it makes a lot of sense for like document based websites in in text based website but it starts to get a little bit hairy when you get into like component and when it moves a little bit from an a website to an app right yeah and that's something that has to be built into your component design and you know there's some things that make that easier for instance in our new syntax site we have like sections with

headers and stuff and some of these components have a builtin header into that component and sometimes that component is is used in one place or another place so sometimes what I've done is I've added a prop which is which level of heading is this going to be and then using a dynamic thing in spelt called spelt element you're able to then swap what the element is based on its actual use case so I can say hey when I use this component The Heading needs to be an H3 based on the hierarchy here of your your document but at the end of the day again it needs to be that outline so what are some other things that are interesting here um headings they're going to be read by a screen reader so sometimes people write paragraph text that's too long or maybe not even descriptive enough of the content itself and when it gets to that it will show it essentially again like an outline and the screen earner is going to start reading that paragraph right like one of the examples that the Ally project used

was that don't use an H2 just for for quotes because it has a nice big font size right and because it says that it's like oh yeah right screen reader is now going to see that quote as a outline section it's going to read that whole quote as being some sort of header for your application so be cognizant of the length of your your text inside of your headers they should be short and they should describe the context of which precedes it right um or that it it predes man language is hard sometimes all right um next here's a here's one that could be controversial you know sometimes again we want to separate the structure from the visual aspect of things how do you feel Wes about classes like an H1 class that gives the styles of an H1 that you could use on other elements how do you feel about that I like I like that a lot because some what you visually want it to look like is not

Chapter 5 8:22

Using H1 classes?

the semantic version of that element right so it's hilarious because I'm I'm sure I have a tweet that's like 10 years old I remember being like lol like H2 with the class of H1 um but that literally makes a lot of so much sense to me now because if you want it to be as big as an H1 and you don't have to call them H1 you could call it you call them anything but it makes so much sense that you would have one through six of of heading values and you just give it a class and that will determine what it actually is printed out on on the screen yes this is something that in my opinion is an easy yes I will do this all day long some other people will say hey don't do this uh you can develop another class but honestly it's a class the class has no semantic meaning here it's just a way of assigning Visual and also you know the other conversation around that would be hey if your visual hierarchy isn't matching the structural hierarchy uh

then that's not good design personally hey you know you're you're the thing that's most important is the the outline design of your headings so as long as that's right the visual design is that's the designer's job whatever it needs to look like to fulfill the Styles if it needs to look like an H1 even though it's an H3 I'm okay with that all day long here's another one this is one that I get wrong uh I I would say I got this wrong up until last week um when Killian from poly pay messaged me about this as being a bug on the syntax website is the logo on your application an H1 I've always made it an H1 I always fig yeah that's what we've been told my entire life I've told to do that right I've been told my entire life oh you can you can put a a title tag in the SVG you can uh hide the text but according to everything that I've been reading some people are okay I should say some people are more hard-lined no on this than

Chapter 6 10:20

Is the logo an H1?

other some people say iffy but from what I've been seeing the the consensus is no the the logo should not be the heading because if you wrap the logo in an H1 as it being the website's name right syntax. FM that's the website's name then every single page on your website the title of that page is syntax. FM I mean the application the screen reader and the user already knows they're on syntax. FM right so the more appropriate H1 would be like for us a tasty treat po web development podcast on the homepage or if you're on the uh podcast page it would be podcasts or something like that it it is the descriptor of the page you are on not the website as a whole so this could confuse screen read scers because it's not essentially describing

the page content it's describing what the website title is right yeah that that makes a lot of sense it's funny because I would I think I don't know who it was SEO people or whatever but they always said H1 it's your website name and H2 would be the like a blog post name but it's really the opp not the opposite but your your logo can just be a a div or you probably throw it in an NA tag if it's in your nav um and then your H1 should be like you said the name of the blog post or the name of the podcast or whatever's whatever that page is for yeah I think I've done this wrong my entire career so if anybody uh is out there who wants to say otherwise please let us know on Twitter but I did quite a bit of research and I found it to be pretty decisive that you shouldn't do that so yeah I've been inspecting element on like tons of sites and you're right like every every website I go to has no H1 tag around the logo yeah it's an interesting one I I it's when I

really got into into this I was like man I've been really doing this wrong my whole life uh very very interesting another one that I didn't necessarily realize is that you can give anything an ARA level so you can give anything the role of an H1 through six using the Arya hyphen level and in fact an example I found on mdn docs was giving a div a role of heading and then an Arya hyphen level of three saying it is going to be then represented as essentially the H3 now me personally I see this I think you probably got other ways to solve this problem yeah seems like a Cod smell it it feels like a Cod smell to me it exists and it does seem to work well and it works fine uh as far as screen readers go but I I was trying to reason about in my mind what is the use case for this that I would say oh this has got to be a div with a roll of heading in an R label of three and I just couldn't put it together for for a lot of like websites people just don't have

Chapter 7 12:45

Giving an ARIA level

access to the templating of of everything like there's like a lot a lot of times we think we're spoiled having access to a full stack where like but I guess if you can add that attribute why don't you just go switch the tag out you know yeah maybe it's another component somewhere down the line or or whatever so yeah it's important I I I feel like with the Arya attributes is if you're reaching for an Arya attribute you should first check can I use semantic semantic HTML and if the answer to that is no because corporate BS or because you literally is is a weird thing like we also have div roll equals button you know if you if you've got to make your button a div then you have to give it a roll right you got to switch it up but you should probably try using the semantic element for it first totally here's another interesting one is it okay to ever use multiple

H1s I've always been told no uh yeah I've always been told no because of it's funny like there's a lot of this like SEO stuff got beaten into us for years and years and like I feel like I don't know if this is true or not but I feel like Google has got to be able to figure out what's happening if there's two H1s like with all the AI power we have in the world is it not able to figure out what's on that page probably yeah I'm going to say technically yes it is possible to use multiple H1s and still be accessible and still be okay for SEO however it does seem to be a little still under discussion people say that the use case for using two H1s is rare but especially in multi-page applications perhaps you have segments of the page that are only ever being visible at once and they're truly two essential separate pages but in the Dom

at the same time then you can use multiple H1s to define those sections or those separate pages as being totally separate areas and that is the specific use case but other other things that I found have have said do not do that just as a a blanket rule so it seems like there is some leeway there but as a general rule you should probably if you're building normalites you should not use multiple H1s it's true like to give it a URL if you're really doing that then those things should be two separate pages yes I agree with you that said another common question well can I use multiple H2S what about h3s and as far as that goes yes you can use as many of those as you want however if you use an H2 it should indicate the starting of a section of a page and an H3 should always be what's next right you should never jump from H so the next BEC an H3 and then if you go back one layer it's

H2 I'm not sure if you know this but the number in the H is how many you should ideally aim to use per page I don't think that is an actual thing I'm going to yeah I tell you straight up I was about to say I hope you're not I hope you're not being G to be in someone's head right now and like three years from now like I think Wes said you should only use two H2S per page yeah don't do that okay uh next one is it okay for headings to be VIs visually hidden this is an interesting question uh because is it is it okay to have uh a heading that perhaps is not on the screen well there's a couple of caveats here yes it is okay for headings to be visually hidden if it does not fit in the design but should be in the hierarchy of the structure of the page if the outline of the page calls for a heading but the design does not yes you can use a heading and make it visually hidden with the caveat of you need to do it in a special way right because if you use

Chapter 8 16:55

Can headings be visually hidden?

display none or visibility hidden or the hidden attribute in HTML that hides it from screen readers making it I mean not useful at all right right there's there's if you have a heading and you want it to be visually hidden only from users who are looking at the page but not people who are listening to the structure of your page then using these properties will make it uh hidden from everything making it completely pointless so there's a technique of which we'll have a code snipp it for but basically you're positioning an absolute you're sending it off the page and you have it a container that is Overflow hidden and you're making that container impossibly small so it doesn't take up any space right that's crazy that that's the fix you know fix y like why is there there should be there really should be something in CSS like the the accessibility project recommends using a CSS clip path with a 50% insight and a one pixel height come on can't we get a

can't we get a visually hidden yes in CSS yes visually hidden but yeah not not hidden from screen readers yeah I know that would be that'd be cool but this is not the type of thing you should do often often your headings should be visually labeled just like they should be labeled in the structure of your page but there are some use cases where it is important to give your sections some heading hierarchial information but the design does not work well with it does not call for it and in that case you can use this visually hidden CSS trick however another thing here is if that element is focusable for some reason right like there's a link in that H1 or something then you need to make sure that when the user tabs to that heading that that heading appears on screen or it is not a part of like the tab order cuz that's the thing if you're tabbing through your website with the keyboard then all of a sudden that Focus Fus ring disappears people are going to be like

where where the heck did that Focus ring go right this is uh a good rundown on CSS tricks from Chris coyer hidden for everyone display none visibility hidden hidden visually but presented for assist of text that's a screen reader only class or that's the visually hidden that we just talked about um or hidden for assist of text but not visually area hidden true that's that's the opposite where you don't want the screen reader to read it but you do want the text to show up on the screen yeah so Arya hidden is is an attribute that you can use that will then again hide something from screener specifically but not visually I I guess I've used that in the past where for whatever reason if I have like duplicate text like if I'm doing some cool CSS effect where I like put two pieces of two like let's say I had the word like syntax podcast and then I wanted to like put it behind and like tilt it a little bit and I would have another paragraph text that says syntax

podcast I wouldn't want it to visually say syntax podcast syntax podcast twice so I would Arya hide the first the second one this is just decorative interesting that was another one I was wondering when would you do that but I'm glad to glad to have that Insight from you okay so benefits again for accessibility this doesn't necessarily matter for keyboard users headings do not do much for keyboard only navigation of websites right but for screen screen readers again this is where headings are really important because they offer an outline to your content and the way screen readers work is that they allow the user to jump to the sections or the areas of the website that they they want to easily and if you don't have that heading structure mapped out or that heading structure is poor the screen order will not be able to function and people who are using them will not be able to navigate your website which is a huge deal okay um they they are they act

Chapter 9 20:46

Benefits of good heading design

as shortcuts for navigating your website you could think of it as like if I had an outline and I were to collapse all the information except for the headings the screen or then allow me to navigate my website by picking the section that I would like to visit and then expanding upon that and they also essentially uh there's another thing in here that we haven't talked about with accessibility called landmarks and we're going to be talking an entire episode about ARA labels so if you're listening to this episode and you're like what about landmarks uh landmarks will be covered in depth when we talk about ARA labels as well um and lastly SEO right craw crawlers like we mentioned off the top will definitely understand your application better if it's well laid out and organized tools what kind of tools you need there's a couple extensions I put in here for headings map one for Firefox one for Chrome uh headings map essentially will outline your website in what looks like essentially an outline using only the headings and allows you to see it explicitly makes it nice and easy my favorite tool for this stuff is

Chapter 10 22:10

Tooling

honestly one of my favorite tools for a lot of things accessibility based but just straight up development which is poly pan polyan is a paid product but it's really good it's a um it's a browser and we actually interviewed Killian from poly pay on syntax before if you would like to learn more about that but polyan is great because one of the views that it gives you is both a landmarks view as well as a heading view of your application and then it gives you nice big red flashing warnings hey hey you skipped a level here hey this doesn't make any sense hey yeah uh what are you doing so poly pain is really great for that you can also look up screen reader Tech to actually use your application and as a screen reader would if you want to get deep into how screen readers work which I would recommend personally I I'm good with a lot of the tools that come in something like poly pain but you know nothing can beat experiencing your application like somebody who's disabled actually does

this headings map is awesome like I just fired it up on my own website and in the footer of every page I have like syntax podcasts tweets Instagram and of course and I put those as h3s probably because I thought they look good dude and now they're being they're being categorized as part of the blog post which they they are not you know like they should be their own H2 tags because they're their own things um and that can sometimes get a little bit tricky with the components because you don't necessarily know where a component is going to live especially if you start nesting components inside of each other but there is I've seen people with react maintain like a like a counter and every time you you Nest a level deeper you can use the counter to increment that would actually be a really good use case for a sync local storage D because it's it's contained within scope you know so you could increment it cuz and then you

can programmatically render out the tag that you need H it's interesting it's interesting uh I I'm going to also link to the issue that Killian raised on the GitHub on the syntax GitHub issue because he gives a bunch of tips and like shows a screenshot of what our H1 system look like before before if you want to see Pros get it wrong like trust me I I thought I knew what I was doing with head ears and then he submitted this and I was so embarrassed to how bad the heading system was and granted I planned on doing a second pass on it but still I didn't realize how bad it was um so I I really appreciate that he submitted this GitHub issue but allowed me to dive deeper into it and um you you can see exactly like some of the issues that were there before we made these changes I've also added a couple of links here for an Ali project a11y pro.com again um really great website or accessibility hyphen developer hyphen guide.com was also a really cool website

that had a lot of information and you may see some conflicting inform because some of this stuff like should you ever use multiple H1s isn't set in stone necessarily but again I think we're trying to be nuanced enough here that you can get the general Vibe so shout out to Killian for opening the issue like this as well because I think a lot of times people are afraid to even talk about accessibility because I feel like there's a lot of name and shame in it and if you get it wrong people love to not everybody but I I feel like there's a part of the industry that is very uh the person hates blind people and we're we're all trying to do a really good job and I'm glad that we're going through it and making sure it's all dialed in before we go live but like this is how you tell somebody hey you're you're being a jerk to some of your website users you know yeah yeah and and I think that goes along too with like nobody likes to be told that they're

doing a bad job at what they do right and again we're all Crafts People we enjoy working on this stuff and we want to make the best stuff possible and so like I don't know I think it all goes under andum assuming positive intent people are trying to do good stuff and sometimes uh you know sometimes everybody slips up so I I was really really um really stoked to see this issue come in and really stoked to take it as an opportunity to immerse myself in some learning opportunities here and share it up with everybody so if we got anything super wrong in this episode I really sincerely did my very best to not misrepresent anything here accessibility stuff is honestly unfortunately harder than it it should be uh but again you know we're building data structures and all sorts of interesting things here kind of needs to be complex but then again we have some weird wacky stuff like this visually hidden class that we have to use so you know it it's a

nuanced conversation so if there's any additions addendums or anything that you think that would further enhance this episode Reach Out to us hit us up on X Twitter Tik Tok flipflop any of that stuff we're around beautiful all right peace

peace

Quote it with credit and a link. Quoting Syntax