HTML / CSS / JavaScript Tutorial

HTML Tutorial

3. Carriage returns and thematic break lines

[this page | pdf | back links]

HTML markup largely ignores carriage returns (i.e. line breaks) within marked up files. Instead, if you want to insert a carriage return you need to insert a <br> tag.


By ‘largely ignores’ we mean that browsers do not render carriage returns as line breaks as such (except if certain styles apply to the element within which they appear, see e.g. the default formatting of the <pre> element). However, carriage returns do affect how HTML handles spaces at the end of the line and at the start of the following line. Leading spaces (i.e. ones on a line before any non-space characters) are typically ignored, as are trailing spaces (i.e. ones on a line after the last non-space character). However, browsers typically insert a 'breaking space' at the end of each line, which often then shows up as a single space. Multiple spaces one after the other are interpreted as a single space. To include more than one space in such instances you need to include a ‘non-breaking space’ as a special character, see here.

For example the following markup:

Hello (followed by two carriage returns)<br><br />    
and again

creates the following output:

Hello (followed by two carriage returns)

Hello again and again

Webpage authors typically put a lot of effort into creating visually appealing material. One way of breaking up text is to insert a thematic break line or horizontal rule, i.e. a <hr> tag, which places a line across the window like:



Contents | Prev | Next | HTML

Desktop view | Switch to Mobile