HOW-TO

How to indent in HTML

Why spaces and Tab do not indent in HTML, text-indent for the first line of a paragraph, margin-left for a whole block, hanging indents, list and blockquote indents, keeping code indentation with <pre>, and indents that look wrong on phones.

4 min read·

Have the file already? Upload it and get a link anyone can open. Free plan, no card.

Get a link free

HTML has no indent tag. Browsers collapse spaces and tabs in your code into a single space, so pressing Tab in the editor changes nothing on the page. Indenting is done with CSS: text-indent for the first line of a paragraph, margin-left or padding-left for a whole block.

Indent the first line of a paragraph

Add this to the <style> block in the <head>: p { text-indent: 2em; }. Every paragraph now starts with its first line pushed in by two letter-widths, like a printed book.

For one paragraph only, put it on that tag: <p style="text-indent: 2em;">Text…</p>. Use em rather than px so the indent grows with the font size.

Books usually skip the indent on the first paragraph after a heading. To match: h2 + p { text-indent: 0; }.

Indent a whole block of text

To move every line of a paragraph or section in from the left, use margin-left: <div style="margin-left: 2em;">…</div>. Use padding-left instead when the block has a background color or border and you want the text pushed in inside it.

For a reusable style, give it a class: .indent { margin-left: 2em; } and then <p class="indent">…</p>. Stack two classes or set 4em for a deeper level.

Hanging indent (for references and bibliographies)

A hanging indent keeps the first line at the left edge and pushes the following lines in. Combine a left padding with a negative text-indent: .hanging { padding-left: 2em; text-indent: -2em; }. This is the format APA and MLA reference lists use.

Lists, quotes and code

  • ✓Lists: browsers indent <ul> and <ol> by 40px of padding-left. Change it with ul { padding-left: 1.5em; }, or set it to 0 to line bullets up with the text above. Nested lists indent one more level by themselves, see how to make a list in HTML.
  • ✓Quotes: <blockquote> is indented on both sides by default (40px each). Use it for quoted text, not as a general indent, because screen readers announce it as a quote.
  • ✓Code: wrap it in <pre><code>…</code></pre>. Inside <pre> the browser keeps every space, tab and line break exactly as typed. tab-size: 4; on the <pre> sets how wide a tab shows (the default is 8).

A few spaces in one spot

For a small gap in the middle of a line, &nbsp; adds one space that does not collapse, and &emsp; adds a wider one. They work, but five &nbsp; in a row is fragile and hard to change later; CSS margin is the better tool for anything you repeat. More on spaces in how to make a line break in HTML.

Indents that look wrong on phones

  • ✓A fixed indent like margin-left: 200px eats half a phone screen. Use em, or cap it: margin-left: min(4em, 10vw);
  • ✓Deeply nested lists or blocks push text off the right edge. Reduce padding-left inside a @media (max-width: 600px) rule.
  • ✓Without <meta name="viewport" content="width=device-width, initial-scale=1"> in the <head>, phones shrink the whole page, so every indent and font looks tiny.

Pages made with AI tools

Claude, ChatGPT and Gemini sometimes indent with rows of &nbsp; or empty spans. If the layout shifts when you edit the text, ask for “indents done with CSS text-indent and margin-left in the <style> tag, no &nbsp; for spacing”.

Share the page as a link

Open the file in a browser to check the indents, then share it. With FileShare Pro you upload the HTML file from the dashboard, copy the link and send it; it opens in any browser and the person opening it needs no account. When you adjust the spacing, upload it to the same link. Related: how to center text in HTML and how to change font in HTML. Sign up free to share your first page.

Frequently asked

How do I indent in HTML?

Use CSS. text-indent: 2em indents the first line of a paragraph; margin-left: 2em indents every line of a block. Spaces and tabs typed in the HTML collapse to one space, so they do not indent.

How do I indent a paragraph in HTML?

Add p { text-indent: 2em; } to the <style> block for every paragraph, or style="text-indent: 2em;" on a single <p> tag.

Why does pressing Tab not indent my text in HTML?

Browsers treat tabs, spaces and line breaks in HTML as one space. Only text inside <pre>, or styled with white-space: pre, keeps them.

How do I make a hanging indent in HTML?

Give the paragraph padding-left: 2em and text-indent: -2em. The first line starts at the edge and the rest are indented.

Got a page to share?

Drop the file, copy the link — live in seconds, free plan included.

Start sharing free