Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

html - Display new line in code tag

Tags:

html

I'm trying to display code but everything is showed in one line. How can I display multiline code tag?

This is my code:

index.html

<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> </head> <title>Documentación: Events</title> <body> <code>     {     "id_tabla":3,     "fecha":"02-09-2015",     "privacidad":0,     "timediff_m": "00"     } </code> </body> 

And this is how is showed in browser:

{"id_tabla":3,"fecha":"02-09-2015","privacidad":0,"timediff_m": "00"} 

Edit

I can only use <code> tag

like image 811
Ricardo Avatar asked Sep 13 '15 13:09

Ricardo


People also ask

How do I add a new line in code?

The <br> tag is a simple and easy way to add line breaks to your HTML code. By adding the <br> tag wherever you want a line break to appear, you can make your code more readable and easier to understand.

What is the use of \n in HTML?

Definition and Usage The \n character matches newline characters.

Which tag creates a new line?

html put newline in text with \n.

How do you start a new line in a paragraph in HTML?

HTML Line Breaks The HTML <br> element defines a line break.


2 Answers

This has already been answered here:

code {    display: block;    white-space: pre-wrap     }
<code>      {      "id_tabla":3,      "fecha":"02-09-2015",      "privacidad":0,      "timediff_m": "00"      }  </code>
like image 106
Avalanche Avatar answered Sep 30 '22 06:09

Avalanche


Use <pre> instead of <code>.

<pre>    {      "id_tabla": 3,      "fecha": "02-09-2015",      "privacidad": 0,      "timediff_m": "00"    }  </pre>

You should use <code> if you want to have something inline and <pre> when you need something multiline.

like image 21
Lipis Avatar answered Sep 30 '22 08:09

Lipis