Ghost Echo
Ghost Echo

Reputation: 2067

How to write out HTML entity name ( , <, >, etc)

How would I write the entity name in HTML and not have it do its function? Example: I'm doing a tutorial and want to tell someone how to use the non-breaking space in their code ( ) So, how to actually write out "&" "n" "b" "s" "p" ";" but have it be fluid with no spaces?

Upvotes: 12

Views: 20409

Answers (4)

gökhan
gökhan

Reputation: 61

JavaScript can be used to change the text of HTML element, below example adds non-blocking space entity character into span element.

<p>A common character entity used in HTML is the non-breaking space: <span id="myid"></span></p>
  <script>
    document.getElementById("myid").textContent= "&nbsp;";
  </script>

Upvotes: 0

Vadym Kovalenko
Vadym Kovalenko

Reputation: 652

You can use &amp; instead of & So &nbsp; will be &amp;nbsp;

Upvotes: 26

chandlermania
chandlermania

Reputation: 360

You could simply use the HTML for the ampersand as in &amp;nbsp; which would display what you're looking for, i.e. &nbsp;

Upvotes: 1

user1327904
user1327904

Reputation:

You will need to write out a part of the code, in this example, I'll use the ampersand. Instead of writing &nbsp;, write out the ampersand, &amp;, and then write nbsp;. Your final result should be &amp;nbsp;, which will display &nbsp; on the webpage.

Upvotes: 4

Related Questions