HTML
 Tag - GeeksforGeeks

Skip to content geeksforgeeks
  • Courses
    • DSA Courses
    • Programming Languages
  • Tutorials
    • Python Tutorial
      • Python Loops and Control Flow
    • Java
      • Java Interview Questions
      • Java Quiz
      • Advance Java
    • Programming Languages
    • System Design
    • Interview Corner
    • Computer Science Subjects
    • DevOps
    • Linux
    • Software Testing
    • Databases
    • Android
    • Excel
    • Mathematics
  • DSA
    • Data Structures
    • Algorithms
      • Analysis of Algorithms
      • Searching Algorithms
      • Sorting Algorithms
    • Practice
      • Company Wise Coding Practice
      • Practice Problems Difficulty Wise
      • Language Wise Coding Practice
      • Curated DSA Lists
    • Company Wise SDE Sheets
    • DSA Cheat Sheets
    • Puzzles
  • Data Science
    • Data Science Packages
    • Data Visualization
    • Data Analysis
  • Web Tech
    • Web Development Using Python
      • Django
      • Flask
    • Cheat Sheets
  • HTML Tutorial
  • HTML Exercises
  • HTML Tags
  • HTML Attributes
  • Global Attributes
  • Event Attributes
  • HTML Interview Questions
  • HTML DOM
  • DOM Audio/Video
  • HTML 5
  • HTML Examples
  • Color Picker
  • A to Z Guide
  • HTML Formatter
Open In App HTML pre Tag Last Updated : 20 Nov, 2024 Summarize Comments Improve Suggest changes Like Article Like Save Share Report Follow

The pre tag in HTML defines a block of preformatted text, preserving spaces, line breaks, and tabs. It displays text in a fixed-width font, which can be styled using CSS. This tag is useful for displaying code, formatted text, and preserving text layout.

HTML <!DOCTYPE html> <html> <body> <pre> This is preformatted text. It preserves spaces and line breaks exactly. </pre> </body> </html>

The <pre> tag is a powerful tool for preserving the exact formatting of text within a web page. By using the <pre> tag, along with related tags like <samp>, <var>, <code>, and <kbd>, you can effectively display preformatted text, sample outputs, variables, code snippets, and keyboard inputs in a visually appealing and semantically meaningful way. Customizing the appearance of the <pre> element with CSS further enhances its versatility and integration into your web design.

Note: The pre tag also supports the Event Attributes in HTML and Global Attributes in HTML.

Tag

Description

<samp>

Defines sample output from a computer program

<var>

Defines a variable

<code>

Defines a piece of computer code.

<kbd>

Defines keyboard input

Using CSS with the <pre> Tag

HTML <!DOCTYPE html> <html> <body> <pre style="font-family: Arial;color: #009900;margin: 25px;"> This is preformatted text. It preserves spaces and line breaks exactly. </pre> </body> </html>

HTML <pre> Tag – FAQs

How does the <pre> tag handle whitespace?

The <pre> tag preserves all whitespace characters, including spaces, tabs, and line breaks. This is different from most HTML elements, which collapse multiple spaces into a single space and ignore line breaks.

Can I use the <pre> tag for displaying code?

Yes, the <pre> tag is commonly used to display code snippets in a readable format. It is often combined with the <code> tag for semantic purposes.

What is the difference between the <pre> tag and the <div> tag?

The key difference is that the <pre> tag preserves whitespace and line breaks exactly as they are in the source code, while the <div> tag does not. The <pre> tag is used for content where formatting needs to be maintained, while the <div> tag is used for general block-level content.

Can I include HTML elements inside a <pre> tag?

Yes, you can include other HTML elements like <b>, <i>, or <span> inside a <pre> tag. However, it’s most commonly used with text or code to maintain formatting. Be cautious with elements that could disrupt the formatting you’re trying to preserve.

Is the <pre> tag a block-level or inline-level element?

The <pre> tag is a block-level element, meaning it takes up the full width available and starts on a new line by default.

S

Shubrodeep Banerjee Follow Improve Previous Article HTML Phrase Tag Next Article HTML 5 <progress> Tag

Similar Reads

How to remove margin introduced in pre tag in bootstrap 4? The problem is that whenever you apply margin space as per your margin value it will give you output. But in <pre> tag if you apply it by keeping any space then it will consider as margin. Because pre is acted vice versa, means as you have written inside the pre tag the output will be the same. Note: The examples will act same with the bootst 2 min read Which Characters Should Be Escaped Inside A "pre" tag? The <pre> tag defines pre-formatted text. Everything (generally, text and code snippets) in a <pre> tag element is displayed in a fixed-width font, and preserves both spaces and line breaks in them. In other words, if anyone wants to show their code snippets on a web page, they can simply enclose their code in the tag. But there are cer 3 min read How to wrap a text in a <pre> tag using CSS ? In this article, we will learn how to wrap a text in a <pre> tag. The <pre> tag is used to display the block of preformatted text which preserves the text spaces, line breaks, tabs, and other formatting characters which are ignored by web browsers. By default, the <pre> tag does not support the <pre> tag. In the case of rend 2 min read Which tag is used to represent progress of a task in HTML & how is it different from <meter> tag ? In this article, we will see which tag is used to represent the progress of a task in HTML. To represent the progress of a task, we will use the <progress> tag. This tag is used to represent the progress of a task. It is also defined how much work is done and how much is left. Syntax: <progress attributes...> </progress> Attribute 2 min read Is container tag same as the empty tag in HTML? If not, why ? In this article, we will see the container tag & empty tag in HTML, along with knowing how they're different from each other. The Container tag is not the same as the empty tag & these are two different categories of tags used in HTML. Container tag: This tag contains 3 parts, namely, the opening tag, content that will be displayed in the b 5 min read HTML | DOM Pre Object The DOM Pre Object is used to represent the HTML <pre> element. The pre element is accessed by getElementById().Properties: width: It is used to set or return the value of the width attribute of the pre element. Syntax: document.getElementById("ID"); Where “id” is the ID assigned to the “pre” tag.Example-1: C/C++ Code <!DOCTYPE html> 1 min read HTML | <pre> width Attribute The HTML <pre> width Attribute is used to specify the maximum number of characters per line. Note: The width Attribute is not supported by HTML5 Syntax: <pre width="number"> Attribute Values: number: It is used to set the maximum number of characters. Example: <!DOCTYPE html> <html> <head> <title> HTML pre width 1 min read Haml | HTML Pre-processor As its name suggests the pre-processor is the first stage of the whole compiling process it includes removing the comments, expanding the macros, the inclusion of the headers, etc. In HTML and CSS when it comes to writing it, It is a bit crucial as we have to do the same job again and again like closing the tab and repeating the same attribute for 3 min read HTML DOM Pre width Property The HTML DOM Pre width Property is used to set or return the value of the width attribute of the <pre> element. Syntax: It returns a pre width Property. preObject.widthIt is used to set the pre width property. preObject.width = "pixels/%"; Property Values: pixels: It sets the width of a predetermined text in terms of pixels.%: It sets the wid 2 min read How to specify a list of pre-defined options for input controls in HTML? Specify a list of pre-defined options for input controls by using the HTML list Attribute. A pre-defined option for input controls using HTML5's <datalist> element, allowing users to select from a predefined list while typing in an input field. Syntax: <input list="datalist_id"/>Example 1: The example below shows, the HTML form with an 2 min read Why <big> tag is not in HTML5 while <small> tag exists ? The <big> tag was discontinued in HTML5 while <small> tag is still in handy because <small> tag is frequently used to represent small prints like footnotes, copyright notices, comments etc. Many alternatives for <big> tag are already available such as <h1>, <h2> and so on. In HTML5 instead of using <big>, y 2 min read Explain the difference between head Tag and header Tag in HTML5 ? The <head> element is a container for metadata and is placed between the <html> and <body> tags. The <header> is for the main content section's introductory elements, like headings or logos and it mainly focuses on what appears at the top of the webpage. <head> ElementThe <head> element is part of the HTML docume 1 min read What is the difference between the <br> Tag and the <p> Tag ? The <br> tag is used to insert a line break, creating a new line within text or content. It doesn't have a closing tag and is a self-closing tag. On the other hand, the <p> tag defines a paragraph, separating blocks of text. It has an opening <p> and a closing </p> tag, allowing for the structured organization of text into p 2 min read Difference between <article> tag and <section> tag Both the tags are semantics in HTML 5. In this article, we will discuss about the <article> and <section> tag. Both the <article> and <section> tags are represented similarly but used for some meaning, that meaning is for the browsers and the developers. Both tags can replace each other as there will be no changes to the out 4 min read What purpose does a <script> tag serve inside of a <noscript> tag? Usage of NoScript tag: The tag defines alternate content that will be displayed if the user has disabled script or browser does not support script. It can be used inside both <head> and <body> tag. Syntax: <noscript> Contents... </noscript> Example: [GFGTABS] HTML <html> <head> <title>wbr Tag</title> 1 min read How to Create a Pre-Filled forms in Node.js ? Pre-Filled forms are those forms that are already filled with desired data. These are helpful when a user wants to update something like his profile, etc. We just create a folder and add a file, for example, index.js. To run this file you need to run the following command. node index.js Filename: SampleForm.ejs C/C++ Code &lt;!DOCTYPE html& 2 min read Vue.js v-pre Directive The v-pre directive is a Vue.js directive used to skip compilation for this element and all its children. You can use this for displaying raw mustache tags. First, we will create a div element with id as app and let's apply the v-pre directive to an element. Further, we can use a heading element to show the data. Syntax: v-pre Parameters: This dire 1 min read How to specify that an option should be pre-selected when the page loads in HTML5? The <option> tag defines an option in a select list. The <option> tag is generally used with the value attribute to specify which value should be sent to the server for further processing. When a drop-down list is created using the <select> element, the first option or the first choice defined by the <option> tag is seen as 2 min read Semantic-UI Popup Pre-Existing Type Semantic UI is an open-source framework that uses CSS and jQuery to build great user interfaces. It is the same as a bootstrap for use and has great different elements to make your website look more amazing. It uses a class to add CSS to the elements. A Popup displays extra facts about the element to the user when he/she hovers over it. Semantic UI 2 min read Mongoose Schema.prototype.pre() API The Mongoose Schema API pre() method is used to add a pre-hook to the mongoose Schema methods and can be used to perform pre Schema method operations. Syntax: Schema.prototype.pre(methodName, options, callback) Parameters: It accepts the following parameters as mentioned above and described below: methodName: It denotes the name of the Schema metho 3 min read Mongoose Query.prototype.pre() API The Mongoose Query API pre() method is used to add a pre-middleware to the mongoose query instance, which can be used in performing pre-query operations. Syntax: Query.prototype.pre(fn) Parameters: It accepts the following parameters as mentioned above and described below: fn: It is a middleware function that is used to perform pre-query operations 2 min read Less.js @plugin At-Rules Pre-Loaded Plugins Less.js is a powerful preprocessor that extends the functionality of CSS by adding programming constructs, such as variables, mixins, and functions. One of the key features of Less.js is the ability to create and use plugins that can be added to a Less.js stylesheet to provide additional functionality. One type of plugin that is particularly useful 3 min read How To Fix Git Error: Pre-Receive Hook Declined? When working with Git repositories, you may encounter an error message that says "Pre-receive hook declined." This error occurs when a pre-receive hook, a type of server-side Git hook, rejects your push. Pre-receive hooks are scripts that run on the server before the push is accepted, and they are often used to enforce rules about commits, branches 3 min read JavaScript Program to Create an Array with a Specific Length and Pre-filled Values In JavaScript, we can create an array with a specific length and pre-filled values using various approaches. This can be useful when we need to initialize an array with default or placeholder values before populating it with actual data. Table of Content Method 1: Using the Array() Constructor and fill() MethodMethod 2: Using a Loop to Initialize V 3 min read Different forms of Pre-rendering in NextJS Next JS is a React-based full-stack framework that enables functionalities like pre-rendering of web pages. Unlike traditional react app where the entire app is loaded on the client, Next JS allows the web page to be rendered on the server, which is great for performance and SEO. You can learn more about Next Js here. Next.js supports two main form 4 min read How to pre-select an input element when the page loads in HTML5? In this article, we are going to pre-select an input element when the page loads i.e. the user doesn't have to click the first text box to start writing on it. When the page is loaded the input is to be pre-selected and the user can start typing directly. This can be done by using the autofocus attribute. It is a boolean attribute that brings an el 1 min read How to pre-compile LESS into CSS ? In this article, we will discuss how to pre-compile the LESS file into a CSS file & will understand its implementation through the example. Introduction: LESS is a simple CSS pre-processor that makes it possible to create manageable, customizable, and reusable style sheets for websites. LESS is a backward-compatible language extension for CSS a 3 min read Pre-request and Post-request scripts in Postman Postman is a powerful tool for testing APIs, and its pre-request and post-request scripts allow you to customize requests and responses. it is an API(utility programming interface) development device that enables construction, taking a look at and altering APIs. It could make numerous varieties of HTTP requests(GET, POST, PUT, PATCH), store environ 4 min read What are pre-request scripts in Postman, and how are they used? Postman is an API(application programming interface) development tool which helps to build, test and modify APIs. It has the ability to make various types of HTTP requests(GET, POST, PUT, PATCH), save environments for later use, converting the API to code for various languages(like JavaScript, Python). In this article, we will learn What are pre-re 2 min read How to Change a Span to Look Like a Pre with CSS? To make a <span> look like a <pre> element with CSS, you need to mimic the behavior of whitespace and styling associated with <pre>. 1. Using Inline CSS Inline CSS is a styling method for HTML pages using the style attribute of an HTML element. Using Inline CSS is not considered a good practice but it depends on the size of the pr 2 min read Article Tags :
  • HTML
  • Web Technologies
  • HTML-Tags
Like three90RightbarBannerImg Explore More We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy Got It ! Lightbox Improvement Suggest changes Suggest Changes Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal. geeksforgeeks-suggest-icon Create Improvement Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all. geeksforgeeks-improvement-icon Suggest Changes min 4 words, max CharLimit:2000

What kind of Experience do you want to share?

Interview Experiences Admission Experiences Career Journeys Work Experiences Campus Experiences Competitive Exam Experiences

Từ khóa » Html5 Text Tag