The Wayback Machine - https://web.archive.org/web/20240829162345/https://www.geeksforgeeks.org/pure-css-form-read-only-inputs/
Open In App

Pure CSS Form Read-Only Inputs

Last Updated : 06 Dec, 2022
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

Readonly is a one of the attributes of <input> element in Pure CSS Forms. It is used to make the input field in a form read-only i.e., we can’t modify the existing content inside the input field whether it is empty or non-empty. The name itself explains the attribute, it makes the input field only readable to the user. t restricts the user from modifying the content present inside the <input> text field, but, user interaction like selecting, copying the content can be performed.

Pure CSS Form Read-Only Inputs Class: There is no class for that we have a predefined attribute that can make any input field read-only and that attribute is  readonly=” ” with empty value.

Syntax:

<form class="pure-form">  
   <input type="..." 
          value="..." readonly="">  
</form>

Below example illustrate the Pure CSS Form Read-Only Inputs

Example 1: In this example, we will see How to find the input field is read-only. The content inside the input field which will be made to read-only will be grayed. The below example shows the word geeksforgeeks can’t be modified and it is grayed, but we can do interactions like selecting the text.

HTML




<!DOCTYPE html>
<html>
 
<head>
    <title>read-only</title>
    <!-- Import Pure CSS files -->
    <link rel="stylesheet"
          href=
          integrity=
"sha384-nn4HPE8lTHyVtfCBi5yW9d20FjT8BJwUXyWZT9InLYax14RDjBj46LmSztkmNP9w"
          crossorigin="anonymous">
</head>
 
<body>
    <h1>Geeksforgeeks</h1>
    <strong>Pure CSS Forms Read-Only Inputs</strong>
    <br><br>
    <form class="pure-form">
        <!-- read-only Input -->
        <label>GeeksforGeeks:
          <input type="text"
                 value="A Computer Science Portal"
                 readonly />
        <label>
    </form>
</body>
 
</html>


 
 

Output: 

 

 

Example 2: In this example, we will Where we can use it. It can be used in the condition that the text inside the text-field should not be changed i.e., it should have a default value. The below example shows that the from(Mumbai) and to(Agra) place can’t be edited for particular Train(Train A) because the Train A only takes the passengers who are originating from Mumbai and destined to Agra. The input tag with value Mumbai and Agra are added with attributes read-only at the last of the input field to make it read-only. You can find that they are grayed.

 

HTML




<!DOCTYPE html>
<html>
 
<head>
    <!-- Import Pure CSS files -->
    <title>read-only</title>
    <link rel="stylesheet"
          href=
          integrity=
"sha384-nn4HPE8lTHyVtfCBi5yW9d20FjT8BJwUXyWZT9InLYax14RDjBj46LmSztkmNP9w"
          crossorigin="anonymous">
</head>
 
<body>
    <h1>Geeksforgeeks</h1>
    <strong>Pure CSS Forms Read-Only Inputs</strong>
    <form class="pure-form pure-form-aligned">
        <fieldset>
            <div class="pure-control-group pure-controls">
                <strong>Train A</strong><br>
                <label for="name">
                  Passenger full-name
                </label>
                <input type="text"
                       class="pure-input"
                       id="name" />
                <br>
                <label for="from">From</label>
                <!-- To make the input field read-only -->
                <input type="text"
                       class="pure-input"
                       id="from"
                       value="Mumbai"
                       readonly />
                <br>
                <label for="to">To</label>
                <input type="text"
                       class="pure-input"
                       id="to"
                       value="Agra"
                       readonly />
                <br>
                <input type="button"
                       class="pure-button pure-button-primary"
                       value="Submit">
            </div>
        </fieldset>
    </form>
</body>
 
</html>


 
 

Output: 

 

Pure CSS Form Read-Only Inputs

Pure CSS Form Read-Only Inputs

 

Note: The disabled attribute is also like readonly but, the only difference is we can’t do any interaction with the content of the field.

 

Reference: https://purecss.io/forms/#read-only-inputs

 



Similar Reads

Pure CSS Form Grouped Inputs
Pure CSS is a framework of CSS. It is a free and open-source tool collection for creating responsive websites and web applications. Pure CSS is developed by Yahoo and is used for creating faster, beautiful, and responsive websites. It can be used as an alternative to Bootstrap. In this article, we will discuss how to create a Grouped inputs form us
2 min read
Pure CSS Inputs
Inputs are important in any webpage form. It is used to take various inputs from the user which are essential in collecting data or information. Following are the various types of inputs in Pure CSS: Required InputsDisabled InputsRead Only InputsRounded InputsCheckboxes and Radios Required Inputs: If you want to mark a form control as required add
3 min read
Pure CSS Rounded Inputs
Pure CSS is a framework of CSS. It is a free and open-source tool collection for creating responsive websites and web applications. Pure CSS is developed by Yahoo and is used for creating faster, beautiful, and responsive websites. It can be used as an alternative to Bootstrap. Pure CSS provides a "pure-input-rounded" class name is used to display
1 min read
Pure.CSS Required Inputs
In some cases when we ask someone to fill a form and few things are optional and few things are a must to fill in that form. In that case, we can use the HTML required in Pure CSS as well. This attribute works with other types of input like radio, checkbox, number, text, etc. Syntax: &lt;input required&gt; Example 1: In this example, we will use th
1 min read
Pure CSS Disabled Inputs
In this article, we will see how to disable the input field in Pure CSS. In some cases, when we ask someone to fill a form few things are activated as well a few things are disabled for their previous choices. In that case, we can use HTML disabled in Pure CSS as well. This attribute works with other types of input like radio, checkbox, number, tex
2 min read
How to find all inputs that are descendants of a form and mark them with a dotted red border in jQuery ?
The task is to find all the inputs that are descendants (child or grandchild) of a form and mark them with a dotted red border using jQuery. Methods and selectors used : parent descendant selector: This selector is used to select all elements that are descendants of a specified element. Syntax: ("parent descendant") css() method: This method is use
2 min read
Create a Read More Read Less Button using HTML CSS and JavaScript
The "read more - read less" button is a commonly used feature that enhances user experience by providing a convenient way to reveal or hide content. The article covers two distinct approaches, including Display Inline and Display Block. Table of Content Using Display InlineUsing Display BlockUsing Display InlineCreate a separate HTML, CSS, and Java
4 min read
Semantic-UI Form Read-Only Field State
Semantic UI is an open-source framework that uses CSS and jQuery to build great user interfaces. It is same as a bootstrap for use and has great different elements to use to make your website look more amazing. It uses a class to add CSS to the elements. A form is the section of a document that contains a number of input fields such as text field,
2 min read
Pure CSS Aligned Form
Pure CSS is a framework of CSS. It is a free and open-source tool collection for creating responsive websites and web applications. Pure CSS is developed by Yahoo and is used for creating faster, more beautiful, and more responsive websites. It can be used as an alternative to Bootstrap. Pure CSS Aligned Form is a type of HTML form that is used to
2 min read
Pure CSS Form Input Sizing
Forms are essential in websites to collect data or information for various purposes. Using Pure CSS Forms, we can create different types of forms. The size of the inputs of forms is always important. So inputs are important in any webpage form. It is used to take various inputs from the user which are essential in collecting data or information. In
2 min read
Pure CSS Stacked Form
Pure CSS is a framework of CSS. It is a free and open-source tool collection for creating responsive websites and web applications. Pure CSS is developed by Yahoo and is used for creating faster, beautiful, and responsive websites. It can be used as an alternative to Bootstrap. In this article, we will discuss how to create a Stacked form using Pur
2 min read
Pure CSS Grids with Multi-Column Form
Pure CSS is a free and open-source CSS framework. It is a collection of tools for creating web applications and responsive web pages. This was developed by Yahoo and is used to make web pages that are more user-friendly, aesthetically pleasing, and quick. It is a potent replacement for Bootstrap. The creation of pure CSS took the responsive design
4 min read
Foundation CSS Abide Ignored Inputs
Foundation CSS is the frontend framework of CSS that is used to build responsive websites, apps, and emails that work perfectly on any device. It is written using HTML, CSS, and JavaScript and is used by many famous companies like Amazon, Facebook, eBay, etc. It uses packages like Grunt and Libsass for fast coding and controlling and Saas compiler
3 min read
Primer CSS Inputs Forms
Primer CSS is a free open-source CSS framework that is built upon systems that create the foundation of the basic style elements such as spacing, typography, and color. This systematic method makes sure our patterns are steady and interoperable with every other. Its approach to CSS is influenced by Object-Oriented CSS principles, functional CSS, an
2 min read
CSS :read-only Selector
The :read-only selector is used to selecting that element which is readable only. The read-only is used to disable the fields. Mainly read-only pseudo-class represent an element that can’t be edited by the user. Syntax: :read-only { // CSS property } Example 1: C/C++ Code &lt;!DOCTYPE html&gt; &lt;html&gt; &lt;head&gt; &lt;style&gt; input:-moz-read
1 min read
Bootstrap 4 | Inputs
List of form control in bootstrap 4. InputTextareaCheckboxesInline CheckboxesRadio ButtonsSelect listForm Control SizingForm Control with Plain TextForm Control File and Range 1. Input type: The input types that Bootstrap 4 supports are text, password, number. datetime, datetime-local, date, month, time, week, email, url, search, tel, and color tha
8 min read
React.js | Uncontrolled Vs Controlled Inputs
In HTML, form elements such as &lt;input&gt;, &lt;textarea&gt;, &lt;select&gt;, etc typically maintain their own state and update it based on user input. In React, a mutable (changeable) state is usually kept in the state property of components. In React forms input value can be of two types according to your choice: uncontrolled and controlled val
3 min read
How to find all button inputs and mark them using jQuery ?
jQuery is a small and fast JavaScript library with a motto: "Write Less And Do More". To use JQuery you can either download the jquery library on your local machine or include the jquery library in your HTML code. Keep in mind that before learning JavaScript you have a basic knowledge of HTML, CSS, and JavaScript. Note: In jQuery button is an exten
2 min read
How to find inputs with an attribute name starting with specific letter or text using jQuery?
In this article, we will learn to find input with an attribute name starting with a specific letter or text. This task is implemented using attributeStartWith selector. attributeStartWith selector: This selector selects elements that have the specified attribute with a value beginning exactly with a given string. It has two arguments i.e attribute
1 min read
How to find all checkbox inputs using jQuery ?
The task is to find all the checkbox input using jQuery. Checkboxes are the square boxes that are ticked when activated, and it is used to select one or more number of choices. Method and Selectors used: :checkbox: This selector is used to select the input element with type = checkbox. .wrap(): This method is used to specify the HTML element around
2 min read
How to find all inputs that don't have color name and appends text to the span next to it using jQuery ?
Given some input elements and the task is to find all inputs that don't have the name = "color" and append text to the span next to it using jQuery. In simple words, we have to find all the input with the name != "color" and then we have to append some text next to the span element. Used Method: next() method: This method is used to return the next
2 min read
How to find all inputs with a value Green and change the text of next sibling span using jQuery ?
The purpose of this article is to find all the inputs with a value "Green" and changes the text of the next sibling span using jQuery. Used Methods - next() method - This method is used to returns the next sibling element of the selected element. text() method - This method is used to returns the text content of the selected elements. Approach - Cr
2 min read
Blaze UI Inputs
Blaze UI is a free open source UI Toolkit that provides an excellent structure for building websites quickly with a scalable and maintainable foundation. All components in Blaze UI are developed mobile-first and rely solely on native browser features, not a separate library or framework. It helps us create a scalable and responsive website quickly
3 min read
Bootstrap 5 Input Group Multiple Inputs
Bootstrap 5 Input Group Multiple Inputs help to take multiple inputs in an input group. Multiple inputs in an input group do not support validations. Bootstrap 5 Input Group Multiple Inputs used Classes: There are no specific classes to create multiple inputs in input group. For creating the input group, we use .input-group class. Syntax: &lt;div c
2 min read
How to compare password and confirm password inputs using express-validator ?
Registration or Sign Up on any website always requires a confirmed password input and it must be the same as the password. It is basically to ensure that the user enters the password full of his senses and there is no conflict happening. This functionality can be implemented anywhere in our code like in the index file or route file but this comes u
4 min read
How to Return a TypeScript Interface that Changes based on Function Inputs ?
In modern TypeScript development, creating adaptable interfaces that can dynamically adjust based on varying inputs is crucial for building flexible and maintainable codebases. TypeScript offers powerful features such as conditional types and mapped types, which enable developers to achieve this level of flexibility. There are several ways to retur
2 min read
How to Use a Typescript Switch on Multiple Inputs ?
Using a TypeScript switch on multiple inputs involves combining input conditions into a single value or using nested switch statements. This approach streamlines logic for handling diverse input scenarios, ensuring efficient and structured code management based on input combinations. Table of Content Combining Inputs into a Single ValueUsing Nested
2 min read
JavaScript TypeError - "X" is read-only
This JavaScript exception is read-only works in strict mode-only and It occurs if a global variable or object property which has assigned to a value, is a read-only property. Message: TypeError: Assignment to read-only properties is not allowed in strict mode (Edge) TypeError: "x" is read-only (Firefox) TypeError: 0 is read-only (Firefox) TypeError
1 min read
How to create mat-button-toggle-group as read only mode in AngularJS ?
Angular Material is a UI component library developed by the Angular team to build design components for desktop and mobile web applications. In order to install it, we need to have angular installed in our project, once you have it, you can enter the below command and can download it. Installation syntax: ng add @angular/material Approach: First, i
2 min read
How to specify an input field is read-only in HTML ?
In this article, we will specify an input field is read-only in HTML. The readonly attribute of &lt;input&gt; element is used to specify that the input field is read-only. If an input is readonly, then it’s content cannot be changed but can be copied and highlighted. It is a boolean attribute. Syntax: &lt;input readonly&gt; Example: This example us
1 min read