HTML & CSS: Separating Text
When writing long pieces (or almost any piece) of content, you will often want ways of separating out the text. There are a variety of ways to accomplish this using HTML and CSS, and we will be outlining three HTML solutions in this tutorial in the form of three different elements.
p
Having paragraphs is very common when writing long pieces of content, and using the p
element to surround paragraphs in HTML is probably the most common method of text separation used on the modern day web. Simply wrap whatever text you want to be in a paragraph in the p
and /p
tags and then they will be separated by default as paragraphs (and if you want to, it's then possible to style the paragraphs using the p
selector). An example of using the p
element is as follows:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
|
It's worth noting that the text I've used for the test paragraphs above is called lorem ipsum text. It's basically filler text with some nice spacing that is often used during a website design process.
br
Another form of separating text is simply using a line break -- like a "carriage return" in most word processing programs. Line breaks are created in HTML by using the 'empty' br
element. When I say it's an 'empty' element, I mean that it's a bit like the link element because it doesn't have an ending tag. In XHTML you'll need (to make your code valid) to use <br/>
instead of <br>
- remember that the slash can also be used in other version of HTML, but it's personal preference. Obviously there are many situations in which you just need to insert a force line-break - but be careful that you don't use these line breaks for design aspects in which having a margin on an element might be better (we'll learn more about these in the future). It's a bit weird on the whole that we specify line breaks in the HTML since they are simply styling and not part of the structure of the document, however the br
element remains in the specification, mainly for ease of use. An example usage is:
1 2 |
|
hr
Sometimes it's useful to have a horizontal rule (line) across the page to separate content out. This is achieved using the empty hr
tag in HTML. As with br
, a forward slash after hr
is optional in most versions of HTML, but it required in XHTML. Also like br
, it's a bit strange that a horizontal line across the page is specified in the HTML of the document, when it really belongs in the CSS - but the hr
element has made it's way into the modern specifications, mainly because of ease of use.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
|
Headings!
While we're talking about some new elements - headings seem to naturally fit into the topic here!
Headings are accomplished in HTML using the different header tags. These range from h1
(the biggest heading on the page) to h6
(the smallest heading on the page).
You then just end the element using the 'normal' ending tags (/h1
, /h2
etc.).
1 2 3 |
|