Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member
The mark element is a brand-new element in HTML5 that is designed to help authors highlight page content, usually for reference purposes. So let's take a look at what the spec has to say about this new element. So here I am in the author view HTML5 specification, and I've navigated to the mark element. And I am just going to scroll down a little bit so we can read the description of this. "The mark element represents a run of text in one document marked or highlighted for reference purposes, due to its relevance in another context.
When used in a quotation or other block of text referred to from the prose, it indicates a highlight that was not originally present." That's the important part, 'not originally present', "but which has been added to bring the reader's attention to a part of the text that might not have been considered important by the original author." So if you're quoting somebody and you want to take a part of that quote and emphasize it for the reader, and it wasn't originally emphasized, then the mark element is perfect for that. And also it has other uses as well. And I am going to scroll down, and I notice here that we have a note that says, "Another example of the mark element is highlighting parts of a document that are matching some search string." So let's say you search a book for a specific phrase or term, what you could do is you could have the search engine not only return the content that somebody searched for, but you could have it wrap the text that they were looking for in the mark element as well to indicate that this is the content that they're looking for.
Although the final version of our Trail Guide file doesn't really use the mark element, nothing is stopping us from experimenting with it. So I am going to go back into our trails file and have a little bit of fun with the mark element to show you guys what it's capable of. All right! So let's come back right into here. Okay. So if you are following along with me, go ahead and open up the trails.htm from the 05_09 folder. And this is actually the finished file, so you might see some content that you didn't see before. All right! So I am going to scroll down a little bit into our trail review for the Northridge Loop, and what I want to look for is the second paragraph right here on line 55. So there are a total of six trailheads.
This is the line that I'm interested in: "Hiking is permitting along all trails." So what I am going to do is I am going to take that section and I am going to wrap that with a mark tag. Now, one of the reasons why I want to do this is I want to show you right off the bat how user agents, browsers, and things like that are essentially implementing the mark tag. Now, our styles don't contain any rules that pertain to the mark tag at all. So all the styling that you are about to see is coming directly from the browser. So I am going to go ahead and save that and preview that in one of my browsers.
And if I scroll down and take a look at the content, it's pretty easy to find where our mark tag is. Now, again, this yellow highlighting is how most browsers are dealing with the mark tag. This is typical. They essentially highlight it using that sort of yellow highlight, just like somebody has come along and highlighted it in a book. Now, that's very nice. It makes it stand out, it emphasizes it, but it's also nonconforming use. I'm not citing another work. I'm not emphasizing a quote, and I'm not showcasing any search results.
So actually, this would be incorrect use. And I am pointing this out because once people see this they're like, oh cool, anytime I need to highlight some text, I'll just use the mark tag, and that is not how you're supposed to use it. That would be semantically incorrect. So I am going to go back into my code and get rid of that. And let's take a look at how we might use this correctly. So since we don't have any search results that we're referencing, we're going to go down to our quote. So in our blockquote where it says, "Northridge Loop is easily the best loop in Ojai! You'll kick yourself if you miss it!" What I am going to do here is I am going to surround the text 'best loop in Ojai!' So that wasn't really emphasized by the original author, but we want to make sure people know that, hey, this person is saying it's the best loop in Ojai.
So that is actually a correct usage for the mark element. So I am going to go ahead and save that and preview that in our browser as well. Now, as I scroll down, I can see in my blockquote, that's really standing out, 'the best loop in Ojai!' there. Now, if you don't like the way that the browser is styling that, you can go ahead and change that. You can just italicize the text. You can choose different background colors for it. You can take the background color off. It's totally up to you in terms of how the mark element is presented. I just wanted to make you familiar with the default presentation in almost all the browsers that are implementing the mark element.
Now, honestly, it hasn't been used a lot yet. It's brand new in HTML5, browsers are implementing it, but I haven't seen a lot of authors using it. In the end, my guess is that we're going to see the mark element being used a good bit in search results. It's a great way to show a visitor exactly where the phrase or the words that they were searching for are in the actual text itself. It's also a great way, as we are using it here, to reference quotes or passages and draw the attention of the reader to a specific part of the passage that wasn't emphasized originally.
Just remember how most browsers style the mark element, and determine for yourself if you want to overwrite the selling with something more consistent with your own site.
Get unlimited access to all courses for just $25/month.Become a member
61 Video lessons · 99216 Viewers
56 Video lessons · 112490 Viewers
71 Video lessons · 81300 Viewers
131 Video lessons · 39038 Viewers
Access exercise files from a button right under the course name.
Search within course videos and transcripts, and jump right to the results.
Remove icons showing you already watched videos if you want to start over.
Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.
Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.