Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member
The pre tag can be used to display preformatted text in HTML. Let's go ahead and make a working copy of pre-1.html; couple of examples here, and we'll call this pre-1-working and I'll open that in my text editor, and you notice that I have down here some preformatted text that I would like it to be displayed exactly like that. And so we bring it up in the browser. You see that it's not doing what I had asked for. It's just displaying it as a regular paragraph. I want it to look like this. So let's just change this p tag to pre, and I am going to come down here and do the same there. I am going to save that and reload in the browser, and now you see that my text is displayed exactly as I intended it. So poetry is one application of this. Let's go ahead and look at another application. Make a working copy of pre-2.html, call that pre-2-working.html, open that in my text editor and here we have an example that is formatting code. Here I have some C code and here I have some HTML code, and you will notice I am using some named entities for some of the characters that would otherwise give us trouble in HTML. So let's go ahead and look at this in the browser, open that in Firefox, and you see it's displaying exactly as we intended. Here's a little main function, the Hello World in C, and here's some HTML. So in cases where we want to display code and want it to display with all of its formatting, all of its indents and all, this is a great technique for doing that. So the pre tag can be very useful for displaying text in its natural formatting.
Get unlimited access to all courses for just $25/month.Become a member
82 Video lessons · 98890 Viewers
61 Video lessons · 86194 Viewers
71 Video lessons · 70032 Viewers
56 Video lessons · 102280 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.
Your file was successfully uploaded.