Home > Web Front-end > CSS Tutorial > How to Display Range Value Using Only HTML and CSS?

How to Display Range Value Using Only HTML and CSS?

Mary-Kate Olsen
Release: 2024-11-14 12:00:04
Original
216 people have browsed it

How to Display Range Value Using Only HTML and CSS?

Displaying Range Value Using HTML5 input type range

Creating a website with a range slider offers a convenient way to adjust values. However, it may be beneficial to display the current slide value in a textbox for easier reference. While jQuery provides a straightforward solution, it is possible to achieve this functionality using only HTML and CSS.

Solution:

To effortlessly display the current range value without JavaScript, implement the following HTML code:

<input type="range" value="24" min="1" max="100" oninput="this.nextElementSibling.value = this.value">
<output>24</output>
Copy after login

In this code:

  • The element defines the range slider with attributes for its value, minimum, and maximum values.
  • The oninput event listener updates the value of the adjacent sibling output element whenever the range slider is adjusted.
  • The element displays the current range value.

Utilizing this method, you can easily display the range value in a textbox without the need for external scripts.

The above is the detailed content of How to Display Range Value Using Only HTML and CSS?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template