{"id":304342,"date":"2020-03-17T07:54:56","date_gmt":"2020-03-17T14:54:56","guid":{"rendered":"https:\/\/css-tricks.com\/?p=304342"},"modified":"2021-08-25T13:29:01","modified_gmt":"2021-08-25T20:29:01","slug":"how-to-create-a-skip-to-content-link","status":"publish","type":"post","link":"https:\/\/css-tricks.com\/how-to-create-a-skip-to-content-link\/","title":{"rendered":"How to Create a \u201cSkip to Content\u201d Link"},"content":{"rendered":"\n

Skip links are little internal navigation links that help users move around a page. It\u2019s possible you\u2019ve never actually seen<\/em> one before because they\u2019re often hidden from view and used as an accessibility enhancement that lets keyboard users and screen readers jump from the top of the page to the content without have to go through other elements on the page first.<\/p>\n\n\n\n

In fact, you can find one right here on CSS-Tricks if you crack DevTools open.<\/p>\n\n\n\n

\"\"<\/figure>\n\n\n\n\n\n\n\n

In my opinion, the best way to implement a skip link is to hide it and then bring it into view when it is focused. So, let\u2019s say we have a link in the HTML:<\/p>\n\n\n\n

<a class=\"skip-to-content-link\" href=\"#main\">\n  Skip to content\n<\/a><\/code><\/pre>\n\n\n\n

\u2026we can give it an absolute position and translate it off the screen:<\/p>\n\n\n\n

.skip-to-content-link {\n  left: 50%;\n  position: absolute;\n  transform: translateY(-100%);\n}<\/code><\/pre>\n\n\n\n

Then we can bring it back into view when it\u2019s in focus and style it up a bit in the process:<\/p>\n\n\n\n

.skip-to-content-link {\n  background: #e77e23;\n  height: 30px;\n  left: 50%;\n  padding: 8px;\n  position: absolute;\n  transform: translateY(-100%);\n  transition: transform 0.3s;\n}\n\n.skip-to-content-link:focus {\n  transform: translateY(0%);\n}<\/code><\/pre>\n\n\n\n

This will hide our link until it is focused and then put it into view when it becomes focused.<\/p>\n\n\n\n