HTMLs Tutorial

HTML Tutorial HTML Tags HTML Basic Tags HTML Attributes HTML Elements HTML Formatting HTML Text Format HTML body tag HTML samp tag HTML script Tag HTML section tag HTML select tag HTML source tag HTML span tag HTML strike tag HTML strong tag HTML style tag HTML sub tag HTML summary tag HTML sup Tag HTML svg tag HTML table tag HTML u tag HTML Headings HTML Paragraphs HTML wbr tag HTML Anchor HTML Image HTML Lists HTML Ordered List HTML Unordered List HTML Form HTML Form input HTML with CSS HTML Layouts HTML References HTML Frames HTML Links Fieldset Tag in HTML Basic HTML Tags Br Tag in HTML Free HTML Templates How to Create a Table in HTML HTML Calendar HTML Card HTML Cellspacing HTML Center Image HTML Checkbox Read-only HTML Cleaner HTML Code for a Tab HTML Comment HTML Compiler HTML Nested Forms HTML Overlay Text on the Image HTML Select Option Default HTML Snake Game HTML Subheader HTML Tab Character dd Tag in HTML How Many HTML Tags are There HTML Align Tag HTML Responsive HTML Tab Code HTML Table Alternate Row Color HTML Table Fix Column Width Contact HTML DL Tag in HTML How to Insert Image in HTML HTML Background Color HTML Dark Mode How to Convert HTML to PNG HTML Data Toggle HTML Email Template HTML Font Color HTML Font Family ID and Class in HTML HTML Tab Space HTML Tab Tag HTML Itemprop HTML Itemscope HTML Form Design HTML Input Only Numbers HTML Textarea HTML to JPG HTML to Markdown Python li Tag in HTML MDN HTML What is the Correct HTML for Making a Hyperlink? What is the Root Element of an HTML Document How to Make a Box in HTML How to Save HTML Files in Notepad How to Align Text in HTML How to Change Font Color in HTML? How to Change Font Size in HTML How to Change Image Size in HTML How to Create a HTML Page How to Create a Link in HTML File? How to Create an HTML File? HR Tag in HTML HTML Base Tag HTML Default Attribute HTML Hyperlink HTML Indent HTML Injection Payloads HTML Input Numbers Only HTML Roadmap HTML Row Height HTML Schedule HTML Space HTML Tab HTML vs HTTP HTML5 API HTML5 Video HTML Collection to Array Text Area in HTML

HTML5 Advance

HTML5 Tutorial HTML5 Tags HTML Button Tag HTML canvas Tag HTML caption Tag HTML City tag HTML Tag HTML5 SVG HTML Event Attribute HTML5 Audio HTML5 Youtube HTML5 Button Tag HTML5 Tags

Misc

How to add JavaScript to HTML How to change font in HTML How to change text color in HTML HTML Date HTML Hide Element HTML Nested Table HTML Reset Button What does HTML stand for? HTML Background Image HTML Tag Div Tag in HTML How to insert Image in HTML How to create a link with no underline in HTML How to insert spacestabs in text using HTMLCSS HTML tag HTML Code HTML Tag HTML Canvas Design a tribute page using HTML and CSS What is a Container tag Font tag in HTML Difference between HTML and DHTML Empty Tag in HTML HTML Button Link Html Line Break Img src HTML Nested List in HTML Placeholder in HTML TD in HTML HTML Space Code HTML Target Attribute HTML Tag Markup Meaning in HTML Border-Collapse in HTML HTML Onclick Online HTML Compiler Convert HTML to PDF HTML Formatter HTML5 - Web Storage HTTP – Responses Container Tag in HTML DL Tag in HTML Horizontal Rule HTML HTML Tab Text Html Table Cell Background Color HTML Table Cell Color HTML Col Width How Many HTML Tags are There Convert String to Unicode Characters in Python HTML Runner HTML Style Attribute HTML Superscript Attribute HTML tabindex Marquee Tag in HTML HTML Dynamic Form HTML side Tag HTML Pattern Attribute HTML q Tag HTML Readonly Base 64 Encoding in HTML Documents Enhancing Data Portability and Security Evo Cam Web Cam HTML Free code camp HTML CSS How to Add a JS File in HTML? How to Add Picture in HTML How to Add the Logo in HTML? How to Add Video in HTML HTML Class Attribute HTML Entities HTML Form Elements HTML Form Templates HTML Marquee Tag HTML Radio Buttons HTML Text box HTML to JSX HTML Tooltip Basic HTML Codes How to Align Image Center in HTML HTML Header Tag HTML Image Tag HTML Next Line

HTML Readonly

Overview

An input element that has the readonly attribute set does not take part in constraint validation as the user cannot alter the input.

Text, search, url, tel, email, password, date, month, week, time, datetime-local, number <input> types and the <textarea> form control elements allow the readonly property. Matching if present on any of these items and input types is the :read-only pseudo class. The :read-write pseudo-class will match if the event that the property is omitted.

The attribute cannot be used with input types that are already non-mutable, like radio and checkbox, or that cannot begin with a value by definition, such as file input types, range, and color, as they both have default values. Additionally, it is not supported on hidden as it is unreasonable to expect a user to complete a form that is hidden. Furthermore, it is not compatible with any button type including the picture.

Note: The readonly property does not apply to other controls (such as buttons and checkboxes), as there is no practical way to distinguish between their being read-only and disabled. Only text controls may be set read-only. 

An input also falls under the :read-only pseudo-class if it possesses the readonly property. On the other hand, inputs that match the :read-write pseudo-class but do not have the attribute set support the readonly attribute.

Interactions between attributes 

Read-only controls are those that can still operate and be focused, whereas disabled controls are those that cannot receive focus, are not submitted with the form, and often cannot function as controls until they are enabled. 

Required has no bearing on inputs that also have the readonly attribute provided since a read-only field cannot have its value altered by human interaction. 

A script is the sole method available for dynamically changing the readonly attribute's value.

Note: The necessary attribute cannot be applied when an input has the readonly property provided. 

Usability

Usability browsers show Readonly. 

Validation constraints 

If an element is read-only, it does not take part in constraint validation and the user cannot edit its value.

Syntax:

<input readonly>

Example: The readonly attribute of HTML is used in this example. 

<!DOCTYPE html> 

<html> 

<head> 

<title>Example for HTML Input readonly Attribute</title> 

</head> 

<body style = "text-align:center">  

<h1 style = "color: red;">

Welcome

</h1> 

<h2>

Example for HTML Input readonly Attribute

</h2> 

<label>Input: 

<!--A readonly input-->

<input type="text" name="value" value = 

"This is the input field readonly" readonly> 

</label> 

</body> 

</html>

Output

HTML Readonly

How it operates 

In this example, a textarea, an email input field, and a username input field are all given the readonly property. Users are not allowed to edit the data in these areas; they can only read it.

As an illustration 

We accept the phone number of user as input in the illustration that follows. We will stop the user from modifying the country code by adding the readonly property on the country code input element. The default value in this case is +91.

Code:

<html>

 <head>

 </head>

 <body>

   <div id="content">

       <!-- readonly attribute -->

     <input type="text" value="+91" readonly>

     <input type="number" placeholder="Enter your phone number">

   </div>

 </body>

</html>

Output:

HTML Readonly

The reason behind readonly 

The readonly attribute's main use is to limit user input for particular form components. 

The readonly element lets users access the material but restricts them from making any modifications, in contrast to the disabled attribute which forbids any interaction.

Disabled versus read-only

The readonly and disabled properties behave similarly on the surface. They prevent the user from changing the value of the element. But there is a significant distinction. When the form is sent to the server then the value of the readonly element will be included. A deactivated element's value won't be sent to the server.

Top Techniques

  1. When you wish to show data that should not be changed by the user then use the readonly property.
  2. Use caution when utilizing readonly for sensitive data as it just stops inadvertent modifications and may be readily circumvented by people with a basic understanding of technology. 
  3. Make sure your forms are compatible with various browsers by testing them frequently.

In summary

One helpful technique for managing user interaction with HTML form components is the readonly property

Web forms that are both safer and easier to utilize may be made by properly integrating this feature.