HTML

Chapter 34: Marking up computer code

Block with <per> and <code>

If the formatting (white space, new lines, indentation) of the code matters, use the pre element in combination with
the code element:

<pre>
 <code>
 x = 42
 if x == 42:
 print "x is … … 42"
 </code>
</pre>

You still have to escape characters with special meaning in HTML (like < with <), so for displaying a block of HTML code (<p> This is a paragraph.</p>), it could look like this:

<pre>
 <code>
 &lt;p>This is a paragraph.&lt;/p>
 </code>
</pre>

Inline with <code>

If a sentence contains computer code (for example, the name of an HTML element), use the code element to mark it
up:

<p>The <code>a</code> element creates a hyperlink.</p>

Recent Posts

Unlocking the Secrets of JSON.stringify(): More Than Meets the Eye

JSON (JavaScript Object Notation) is a lightweight data-interchange format widely used in web development. At…

7 months ago

How to Handle AJAX GET/POST Requests in WordPress

AJAX (Asynchronous JavaScript and XML) is a powerful technique used in modern web development that…

8 months ago

Page Speed Optimization: Post-Optimization Dos and Don’ts

Introduction After successfully optimizing your website for speed, it's essential to maintain and build upon…

8 months ago

Ultimate Guide to Securing WordPress Folders: Protect Your Site from Unauthorized Access

Securing your WordPress folders is crucial to safeguarding your website from unauthorized access and potential…

9 months ago

HTML CSS PHP File Upload With Circle Progress Bar

Creating a file upload feature with a circular progress bar involves multiple steps. You'll need…

10 months ago

Using WP Rocket with AWS CloudFront CDN

Integrating WP Rocket with AWS CloudFront CDN helps to optimize and deliver your website content…

10 months ago