issue is a huge pet peeve of mine and something that so many sites get wrong, and that is that they have their tab order all messed up and not in the ways that you may be thinking. Let's take this simple site for example. You can see when I'm tabing through right here, I'm on these other buttons, which makes a lot of sense. And if I start all the way at the start of my site, you can see the first thing I hit is this giant menu button, which is fine. When I click tab again, you think it would go down to this other button right here. But when I click it, you notice my tab seems to completely disappear. Now, if I click shift and tab, that brings me backwards. And you'll notice it brings me back to the correct location. And if I click tab enough times, eventually it'll make me to that other button. So, where is my tab at between all these different times? Cuz I have to hit it a bunch of times to be able to get between these different things. Well, if we look at our actual code over here, you can see we have our site. The first thing that shows up is that button that we tab onto. That makes sense. Then we have this overlay. aside element, which is like our drawer that's happening. And this is rendering on our screen even though it's off the screen. You see how it slides in and then slides off, but it's still being rendered, which means that what's happening is it's tabbing through every element on this thing that we can't even see on our page. Then after it gets through all that, it finally moves through and starts tabbing through all these buttons down here. So, this is our problem. When we have content that is off the screen or not visible, we want to make sure it's impossible to tab onto that content. Now, this is really easy for us to do. All we need to do is just add the inert property directly onto there. The inert property essentially prevents you from interacting with this content in any way and it completely hides it from screen readers. That one fix solves all of our problems. For example, if we're on this other button and we click shift tab, we go back up to here. When I click tab, I move down to the next one. I've immediately completely removed this drawer sidebar thing from my tab indexing. Now, when I have this open, I obviously want to be able to tab through it because right now I can't interact with it or do anything. It pretends like it doesn't exist. So, inside my JavaScript, what I want to do is where I have my drawer here, when I open it, I want to set that inert property to false. And I want to do the exact opposite and set it to true whenever I close it. So now when I open this up, I can tab around inside this content just fine. And when I close it, we'll know that my tab lets me skip right over that content because it essentially that inert keyword makes it pretend like it doesn't exist at all. Now, we do still have a problem though with this site. And that is let's say that I'm inside here and I'm tabing around and everything's working great. But the problem is if I just make my screen a little bit wider and a little bit less zoomed in, we'll be able to see this. If you take a look at these buttons right here when I'm tabbing through, you'll notice that I'm actually able to tab and interact with content that's behind the thing that's supposed to be covering my screen. This is really common with things like modals or pop-ups or drawers like this. I want to make sure I can't interact with the content behind here. But right now, I can clearly interact with all these buttons using the tab keyboard. So again, that inner property is going to be what saves us. So what we can do is we can just wrap all the content that we want to hide. In our case, everything except for our aside here. So we can just take our aside and overlay and move that outside of this container. This we just called site. So this site container contains literally everything. And then this is just the content that's outside of our site. And now in our JavaScript, we have that site variable right here. We can set the inert on this one to true. And down here, we can set it to false when we close our modal. So essentially, we're flip-flopping which things are inert. While my sidebar is open, the section right over here, if I just expand this further, the section in here is not inert. And I'm able to tab through all this just fine. But when it's closed, that section is inert. And I can only tab through the content inside my section. So this is a great way for me to flip-flop between these two to work with them. Another thing you could do is use the dialogue element in HTML. I have a full video covering it. I'll link it in the cards in description, but that automatically handles all the inert stuff for you, so you don't have to manually do it yourself. Now, if you're enjoying this content, I highly recommend you check out the full check sheet in both dark and light mode. Like I said, it's got over 80 different things on it, and you can just go through it as a checklist anytime that you're adding features or testing out your site. Now, the next thing I want to
something that so many developers get wrong, including myself when I was first getting started. I've taken a very heavily modified version of this project, which is from my CSS simplified course. If you're interested, I'll link it in the description for you so you can check out the full course where you build projects like this and many others. But essentially, what I have here is a simple system that you've seen on a lot of sites. We have some text and we have an image. We then have the flipped version, image, then text, and then again, we have text and image. Super simple. And you can see if I tab through this content, it works fine. Everything that I tab to is highlighted in this giant red. So you can see this read more button. Then we move over to do something, move back to do something, read more, do something. Super straightforward. It's left to right, top to bottom, just like you would normally expect in a website. The problem is though that the mobile view of our website does not actually work like you expect. Let's shrink this down to mobile. And now you'll notice that we just stack everything. It goes text, image, text, image, just like you would expect in a mobile version of this exact same site. So, if we try to tab through this content, you can see first read more. That's great. Then it goes to this do something. And you'd think it would go to this read more button next, but instead it skips that and goes down to this button here. And then it jumps back up to the read more button. And then it finally jumps down to read more and the do something button again. So you can see we're skipping where we should be at. And this is specifically because we're rearranging the order of our HTML elements inside of CSS, but we're not reordering them in our HTML. If we take a look at our actual code for this section, you can see we have three section elements. one section, two section, three section. Those represent, if we expand this out a little ways, these three sections of content and one of them is labeled as section reversed order. Now, if we look at the code inside this section, I'll just minimize down so we can see the important part. You'll notice first we have our image and then we have our text, which is the exact order we have our content inside of here. That makes sense. But on a smaller screen size, you can see that I'm changing the order of this. I'm using flex direction column reverse. All that does is it flips the order of how these things render, but it doesn't change the order of your HTML. And the only thing that your tabbing keyboard cares about is the order of the HTML. So, we rearranged the order visually, but we didn't change the order in HTML. This is something that can be a massive problem because now things that are laid out in a specific visual order change completely in the actual order that they are in the HTML. Realistically, what I should be doing in this example is I should have this section completely flipped where the image is second and my text is first. So, it's just like all my other pieces of content where the text comes before the image. But then on large screen sizes, I flip the order of them. So, this should essentially be reversed to a min width just like that. And we can specify that this should be row reversed just like that. And now you can see we get the exact same layout that we did before. But when we tab through this, the order is a little bit more logical. You can see it goes read more, then it goes button, then button, then read more, then button. So, it has the exact same flow that it did before. And on a small screen size, we still get the same exact order. You get read more, button, read more, button. So, it's important to think about not only the actual structure of your HTML, but also how that content is visually showed on your page. Because if those things are too different from each other, it could really change how your tab