From 1bfb01713a86d7c3d241b742691314eaa1045066 Mon Sep 17 00:00:00 2001 From: Masahiro FUJIMOTO Date: Sun, 13 Feb 2022 12:38:18 +0900 Subject: を移行 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- files/ja/web/html/element/input/range/index.html | 501 ----------------------- files/ja/web/html/element/input/range/index.md | 501 +++++++++++++++++++++++ 2 files changed, 501 insertions(+), 501 deletions(-) delete mode 100644 files/ja/web/html/element/input/range/index.html create mode 100644 files/ja/web/html/element/input/range/index.md diff --git a/files/ja/web/html/element/input/range/index.html b/files/ja/web/html/element/input/range/index.html deleted file mode 100644 index 1ba58f6167..0000000000 --- a/files/ja/web/html/element/input/range/index.html +++ /dev/null @@ -1,501 +0,0 @@ ---- -title: -slug: Web/HTML/Element/input/range -tags: - - Element - - Forms - - HTML - - HTML forms - - HTML input tag - - HTML フォーム - - Input - - Range - - Reference - - Web - - slider - - スライダー - - フォーム - - 要素 -translation_of: Web/HTML/Element/input/range -browser-compat: html.elements.input.input-range ---- -
{{HTMLRef("Input_types")}}
- -

{{HTMLElement("input")}} 要素の range 型は、ユーザーに特定の値より小さくなく、別な特定の値より大きくない数値を指定させるために使用します。しかし、厳密な値が重要であるとはされません。これは通常、 {{HTMLElement('input/number', 'number')}} 入力型のようなテキスト入力ボックスではなく、スライダーやダイアルコントロールを用いて表現されます。この種のウィジェットは厳密なものではないので、コントロールの正確な値が重要でない限り、通常は使用するべきではありません。

- -
{{EmbedInteractiveExample("pages/tabbed/input-range.html", "tabbed-standard")}}
- -

ユーザーのブラウザーが range 型に対応していない場合は、 {{HTMLElement('input/text', 'text')}} 入力で代替されて扱われます。

- - - - - - - - - - - - - - - - - - - - - - - - -
{{anch("Value", "値")}}選択された数値を表す文字列を含む {{domxref("DOMString")}}。数値として値を取得するには {{domxref("HTMLInputElement.valueAsNumber", "valueAsNumber")}} を使用してください。
イベント{{event("change")}} および {{event("input")}}
対応している共通属性{{htmlattrxref("autocomplete", "input")}}, {{htmlattrxref("list", "input")}}, {{htmlattrxref("max", "input")}}, {{htmlattrxref("min", "input")}}, {{htmlattrxref("step", "input")}}
IDL 属性list, value, valueAsNumber
メソッド{{domxref("HTMLInputElement.stepDown", "stepDown()")}} および {{domxref("HTMLInputElement.stepUp", "stepUp()")}}
- -

検証

- -

利用可能なパターン検証はありません。しかし、以下の形で自動検証が行われます。

- - - -

- -

{{htmlattrxref("value", "input")}} 属性は、選択された数値を表す文字列が入った {{domxref("DOMString")}} です。値は空文字列 ("") にはなりません。既定値は指定された最大値と最小値の中間値で、ただし最大値が最小値を下回っている場合は、既定値は min 属性の値に設定されます。既定値を特定するアルゴリズムは次の通りです。

- -
defaultValue = (rangeElem.max < rangeElem.min) ? rangeElem.min
-               : rangeElem.min + (rangeElem.max - rangeElem.min)/2;
- -

最小値よりも小さな値を設定しようとすると、最小値に設定されます。同様に、最大値よりも大きな値を設定しようとすると、最大値に設定される結果になります。

- -

追加の属性

- -

すべての {{HTMLElement("input")}} 型で共通する属性に加え、 range 型の入力欄は次の属性にも対応しています。

- - - - - - - - - - - - - - - - - - - - - - - - - - -
属性説明
{{anch("list")}}オプションで自動補完の定義済みの選択肢を含む <datalist> 要素の id
{{anch("max")}}許可されている最大値
{{anch("min")}}許可されている最小値
{{anch("step")}}ユーザーインターフェイスと検証の両方で使用される刻み値
- -

{{page("/ja/docs/Web/HTML/Element/input/text", "attr-list", 0, 1, 2)}}

- -

対応しているブラウザーで、範囲のオプションがどのように表示されるかの例としては、以下のハッシュマーク付き範囲コントロールを参照してください。

- -

max

- -

許可されている値の範囲の最大値です。要素に入力された {{htmlattrxref("value", "input")}} がこれを超えた場合、要素は制約検証に失敗します。 max 属性の値が数値でない場合、要素は最大値を持ちません。

- -

この値は min 属性の値より大きいか、等しくしなければなりません。 HTML の max 属性を参照してください。

- -

min

- -

許可されている値の範囲の最小値です。要素の {{htmlattrxref("value", "input")}} がこれより小さい場合、要素は制約検証に失敗します。 min 属性の値が数値でない場合、要素は最小値を持ちません。

- -

この値は min 属性の値より小さいか、等しくしなければなりません。 HTML の min 属性を参照してください。

- -

step

- -

{{page("/ja/docs/Web/HTML/Element/input/number", "step-include")}}

- -

range 入力欄の既定の刻み値は 1 であり、刻みの基準値が整数ではない場合を除いて、整数の入力のみを許可します。例えば、 min に -10 を、 value に 1.5 を設定した場合、 step が 1 の場合は正の方向に 1.5, 2.5, 3.5,... など、負の方向に -0.5, -1.5, -2.5,... などのみが許可されます。 HTML の step 属性を参照してください。

- -

標準外の属性

- - - - - - - - - - - - - - -
属性説明
{{anch("orient")}}範囲のスライダーの向きを設定します。 Firefox のみ。
- -

orient {{non-standard_inline}}

- -

CSS の標準外の -moz-orient non-standard プロパティと同様に {{htmlelement('progress')}} および {{htmlelement('meter')}} 要素に影響を与える orient 属性は、範囲スライダーの向きを定義する定義します。値は horizontal が範囲を水平方向に描画することを、 vertical が範囲を垂直に描画することを意味します。

- -
-

メモ: input 型の属性のうち、 accept, alt, checked, dirname, formaction, formenctype, formmethod, formnovalidate, formtarget, height, maxlength, minlength, multiple, pattern, placeholder, readonly, required, size, src, width は範囲入力には適用されません。これらの属性が含まれた場合は無視されます。

-
- -

- -

number 型がユーザーに数値を入力させ、任意で値を最小値と最大値の間に強制することができるものですので、具体的な値を入力する必要があります。 range 入力型は、どの値が選択されているかをユーザーが気にする、または知る必要がない場合に、ユーザーに値を尋ねることができます。

- -

range 入力欄がよく使用される場合の例をいくつか示します。

- - - -

原則として、ユーザーが実際の数値自体よりも最大値と最小値の間のパーセント値に関心がある場合は、 range 入力が最有力候補になります。例えば、ホームステレオの音量制御では、ユーザーは通常「音量を0.5に設定する」ではなく、「音量を最大値の半分くらいに設定する」と考えます。

- -

最小値と最大値の指定

- -

既定では、最小値は0で最大値は100です。これが望むものでないのであれば、 {{htmlattrxref("min", "input")}} や {{htmlattrxref("max", "input")}} 属性の値を変更することで、簡単に範囲を変更することができます。浮動小数点値にすることもできます。

- -

例えば、ユーザーに -10 から 10 までの値を尋ねるのであれば、次のようにすることができます。

- -
<input type="range" min="-10" max="10">
- -

{{EmbedLiveSample("Specifying_the_minimum_and_maximum", 600, 40)}}

- -

値の精度の設定

- -

By default, the granularity, is 1, meaning that the value is always an integer. You can change the {{htmlattrxref("step")}} attribute to control the granularity. For example, If you need a value between 5 and 10, accurate to two decimal places, you should set the value of step to 0.01:

- -
-
<input type="range" min="5" max="10" step="0.01">
- -

{{EmbedLiveSample("Granularity_sample1", 600, 40)}}

-
- -

If you want to accept any value regardless of how many decimal places it extends to, you can specify a value of any for the {{htmlattrxref("step", "input")}} attribute:

- -
-
<input type="range" min="0" max="3.14" step="any">
- -

{{EmbedLiveSample("Granularity_sample2", 600, 40)}}

- -

This example lets the user select any value between 0 and π without any restriction on the fractional part of the value selected.

-
- -

ハッシュマークとラベルの追加

- -

The HTML specification gives browsers some flexibility on how to present the range control. Nowhere is this flexibility more apparent than in the area of hash marks and, to a lesser degree, labels. The specification describes how to add custom points to the range control using the {{htmlattrxref("list", "input")}} attribute and a {{HTMLElement("datalist")}} element, but does not have any requirements or even recommendations for standardized hash or tick marks along the length of the control.

- -

範囲コントロールのモックアップ

- -

Since browsers have this flexibility, and to date none support all of the features HTML defines for range controls, here are some mockups to show you what you might get on macOS in a browser which supports them.

- -
簡素な範囲コントロール
- -

This is what you get if you don't specify a {{htmlattrxref("list", "input")}} attribute, or if the browser doesn't support it.

- - - - - - - - - - - - - - - - - - - - - -
HTMLExamples
-
-<input type="range">
-
Screenshot
Screenshot of a plain slider control on macOS
Live
{{EmbedLiveSample("An_unadorned_range_control",200,55,"","", "nobutton")}}
- -
ハッシュマーク付きの範囲コントロール
- -

This range control is using a list attribute specifying the ID of a {{HTMLElement("datalist")}} which defines a series of hash marks on the control. There are eleven of them, so that there's one at 0% as well as at each 10% mark. Each point is represented using an {{HTMLElement("option")}} element with its {{htmlattrxref("value", "option")}} set to the range's value at which a mark should be drawn.

- - - - - - - - - - - - - - - - - - - - - -
HTMLExamples
-
-<input type="range" list="tickmarks">
-
-<datalist id="tickmarks">
-  <option value="0"></option>
-  <option value="10"></option>
-  <option value="20"></option>
-  <option value="30"></option>
-  <option value="40"></option>
-  <option value="50"></option>
-  <option value="60"></option>
-  <option value="70"></option>
-  <option value="80"></option>
-  <option value="90"></option>
-  <option value="100"></option>
-</datalist>
-
-
Screenshot
Screenshot of a plain slider control on macOS
Live
{{EmbedLiveSample("A_range_control_with_hash_marks_and_labels",200,55,"","", "nobutton")}}
- -
ハッシュマークとラベル付きの範囲コントロール
- -

You can add labels to your range control by adding the {{htmlattrxref("label", "option")}} attribute to the {{HTMLElement("option")}} elements corresponding to the tick marks you wish to have labels for.

- - - - - - - - - - - - - - - - - - - - - -
HTMLExamples
-
-<input type="range" list="tickmarks">
-
-<datalist id="tickmarks">
-  <option value="0" label="0%"></option>
-  <option value="10"></option>
-  <option value="20"></option>
-  <option value="30"></option>
-  <option value="40"></option>
-  <option value="50" label="50%"></option>
-  <option value="60"></option>
-  <option value="70"></option>
-  <option value="80"></option>
-  <option value="90"></option>
-  <option value="100" label="100%"></option>
-</datalist>
-
-
Screenshot
Screenshot of a plain slider control on macOS
Live
{{EmbedLiveSample("A_range_control_with_hash_marks_and_labels",200,55,"","", "nobutton")}}
- -
-

Note: Currently, no browser fully supports these features. Firefox doesn't support hash marks and labels at all, for example, while Chrome supports hash marks but doesn't support labels. Version 66 (66.0.3359.181) of Chrome supports labels but the {{htmlelement("datalist")}} tag has to be styled with CSS as its {{cssxref("display")}} property is set to none by default, hiding the labels.

-
- -

方向の変更

- -
-

By default, if a browser renders a range input as a slider, it will render it so that the knob slides left and right. When supported, we will be able to make the range vertical, to slide up and down with CSS by declaring a height value greater than the width value. This is not actually implemented yet by any of the major browsers. (See Firefox {{bug(981916)}}, Chrome bug 341071). It also, perhaps, may still be under discussion.

- -

In the meantime, we can make the range vertical by rotating it using CSS transforms, or, by targeting each browser engine with their own method, which includes setting the {{cssxref('appearance')}} to slider-vertical, by using a non-standard orient attribute in Firefox, or by changing the text direction for Internet Explorer and Edge.

- -

Consider this range control:

- -
-
<input type="range" id="volume" min="0" max="11" value="7" step="1">
-
- -

{{EmbedLiveSample("Orientation_sample1", 200, 200, "orientation_sample1.png")}}

- -

This control is horizontal (at least on most if not all major browsers; others might vary).

-
- -

Standards

- -

According to the specification, making it vertical requires adding CSS to change the dimensions of the control so that it's taller than it is wide, like this:

- -
-

CSS

- -
#volume {
-  height: 150px;
-  width: 50px;
-}
- -

HTML

- -
<input type="range" id="volume" min="0" max="11" value="7" step="1">
- -

結果

- -

{{EmbedLiveSample("Orientation_sample2", 200, 200, "orientation_sample2.png")}}

-
- -

Unfortunately, no major browsers currently support vertical range controls directly.

- -

transform: rotate(-90deg)

- -

You can, however, create a vertical range control by drawing a horizontal range control on its side. The easiest way is to use CSS: by applying a {{cssxref("transform")}} to rotate the element, you can make it vertical. Let's take a look.

- -

HTML

- -

The HTML needs to be updated to wrap the {{HTMLElement("input")}} in a {{HTMLElement("div")}} to let us correct the layout after the transform is performed (since transforms don't automatically affect the layout of the page):

- -
<div class="slider-wrapper">
-  <input type="range" min="0" max="11" value="7" step="1">
-</div>
- -

CSS

- -

Now we need some CSS. First is the CSS for the wrapper itself; this specifies the display mode and size we want so that the page lays out correctly; in essence, it's reserving an area of the page for the slider so that the rotated slider fits into the reserved space without making a mess of things.

- -
.slider-wrapper {
-  display: inline-block;
-  width: 20px;
-  height: 150px;
-  padding: 0;
-}
-
- -

Then comes the style information for the <input> element within the reserved space:

- -
.slider-wrapper input {
-  width: 150px;
-  height: 20px;
-  margin: 0;
-  transform-origin: 75px 75px;
-  transform: rotate(-90deg);
-}
- -

The size of the control is set to be 150 pixels long by 20 pixels tall. The margins are set to 0 and the {{cssxref("transform-origin")}} is shifted to the middle of the space the slider rotates through; since the slider is configured to be 150 pixels wide, it rotates through a box which is 150 pixels on each side. Offsetting the origin by 75px on each axis means we will rotate around the center of that space. Finally, we rotate counter-clockwise by 90°. The result: a range input which is rotated so the maximum value is at the top and the minimum value is at the bottom.

- -

{{EmbedLiveSample("transform_rotate-90deg", 200, 200, "orientation_sample3.png")}}

- -

appearance property

- -

The {{cssxref('appearance')}} property has a non-standard value of slider-vertical that, well, makes sliders vertical.

- -

HTML

- -

We use the same HTML as in the previous examples:

- -
<input type="range" min="0" max="11" value="7" step="1">
-
- -

CSS

- -

We target just the inputs with a type of range:

- -
input[type="range"] {
-  -webkit-appearance: slider-vertical;
-}
- -

{{EmbedLiveSample("appearance_property", 200, 200)}}

- -

orient attribute

- -

In Firefox only, there is a non-standard orient property.

- -

HTML

- -

Use similar HTML as in the previous examples, we add the attribute with a value of vertical:

- -
<input type="range" min="0" max="11" value="7" step="1" orient="vertical">
-
- -

{{EmbedLiveSample("orient_attribute", 200, 200)}}

- -

writing-mode: bt-lr;

- -

The {{cssxref('writing-mode')}} property should generally not be used to alter text direction for internationalization or localization purposes, but can be used for special effects. 

- -

HTML

- -

We use the same HTML as in the previous examples:

- -
<input type="range" min="0" max="11" value="7" step="1">
-
- -

CSS

- -

We target just the inputs with a type of range, changing the writing mode from the default to bt-lr, or bottom-to-top and left-to-right:

- -
input[type="range"] {
-  writing-mode: bt-lr;
-}
- -

{{EmbedLiveSample("writing-mode_bt-lr", 200, 200)}}

- -

Putting it all together

- -

As each of the above examples works in different browsers, you can put all of them in a single example to make it work cross browser:

- -

HTML

- -

We keep the orient attribute with a value of vertical for Firefox:

- -
<input type="range" min="0" max="11" value="7" step="1" orient="vertical">
-
- -

CSS

- -

We target just the inputs with a type of range, changing the writing mode from the default to bt-lr, or bottom-to-top and left-to-right, for Edge and Internet Explorer, and add -webkit-appearance: slider-vertical for all -webkit-based browsers:

- -
input[type="range"] {
-  writing-mode: bt-lr;
-  -webkit-appearance: slider-vertical;
-}
- -

{{EmbedLiveSample("Putting_it_all_together", 200, 200)}}

- -

仕様書

- -

{{Specifications}}

- -

ブラウザーの互換性

- -

{{Compat}}

- -

関連情報

- - diff --git a/files/ja/web/html/element/input/range/index.md b/files/ja/web/html/element/input/range/index.md new file mode 100644 index 0000000000..1ba58f6167 --- /dev/null +++ b/files/ja/web/html/element/input/range/index.md @@ -0,0 +1,501 @@ +--- +title: +slug: Web/HTML/Element/input/range +tags: + - Element + - Forms + - HTML + - HTML forms + - HTML input tag + - HTML フォーム + - Input + - Range + - Reference + - Web + - slider + - スライダー + - フォーム + - 要素 +translation_of: Web/HTML/Element/input/range +browser-compat: html.elements.input.input-range +--- +
{{HTMLRef("Input_types")}}
+ +

{{HTMLElement("input")}} 要素の range 型は、ユーザーに特定の値より小さくなく、別な特定の値より大きくない数値を指定させるために使用します。しかし、厳密な値が重要であるとはされません。これは通常、 {{HTMLElement('input/number', 'number')}} 入力型のようなテキスト入力ボックスではなく、スライダーやダイアルコントロールを用いて表現されます。この種のウィジェットは厳密なものではないので、コントロールの正確な値が重要でない限り、通常は使用するべきではありません。

+ +
{{EmbedInteractiveExample("pages/tabbed/input-range.html", "tabbed-standard")}}
+ +

ユーザーのブラウザーが range 型に対応していない場合は、 {{HTMLElement('input/text', 'text')}} 入力で代替されて扱われます。

+ + + + + + + + + + + + + + + + + + + + + + + + +
{{anch("Value", "値")}}選択された数値を表す文字列を含む {{domxref("DOMString")}}。数値として値を取得するには {{domxref("HTMLInputElement.valueAsNumber", "valueAsNumber")}} を使用してください。
イベント{{event("change")}} および {{event("input")}}
対応している共通属性{{htmlattrxref("autocomplete", "input")}}, {{htmlattrxref("list", "input")}}, {{htmlattrxref("max", "input")}}, {{htmlattrxref("min", "input")}}, {{htmlattrxref("step", "input")}}
IDL 属性list, value, valueAsNumber
メソッド{{domxref("HTMLInputElement.stepDown", "stepDown()")}} および {{domxref("HTMLInputElement.stepUp", "stepUp()")}}
+ +

検証

+ +

利用可能なパターン検証はありません。しかし、以下の形で自動検証が行われます。

+ + + +

+ +

{{htmlattrxref("value", "input")}} 属性は、選択された数値を表す文字列が入った {{domxref("DOMString")}} です。値は空文字列 ("") にはなりません。既定値は指定された最大値と最小値の中間値で、ただし最大値が最小値を下回っている場合は、既定値は min 属性の値に設定されます。既定値を特定するアルゴリズムは次の通りです。

+ +
defaultValue = (rangeElem.max < rangeElem.min) ? rangeElem.min
+               : rangeElem.min + (rangeElem.max - rangeElem.min)/2;
+ +

最小値よりも小さな値を設定しようとすると、最小値に設定されます。同様に、最大値よりも大きな値を設定しようとすると、最大値に設定される結果になります。

+ +

追加の属性

+ +

すべての {{HTMLElement("input")}} 型で共通する属性に加え、 range 型の入力欄は次の属性にも対応しています。

+ + + + + + + + + + + + + + + + + + + + + + + + + + +
属性説明
{{anch("list")}}オプションで自動補完の定義済みの選択肢を含む <datalist> 要素の id
{{anch("max")}}許可されている最大値
{{anch("min")}}許可されている最小値
{{anch("step")}}ユーザーインターフェイスと検証の両方で使用される刻み値
+ +

{{page("/ja/docs/Web/HTML/Element/input/text", "attr-list", 0, 1, 2)}}

+ +

対応しているブラウザーで、範囲のオプションがどのように表示されるかの例としては、以下のハッシュマーク付き範囲コントロールを参照してください。

+ +

max

+ +

許可されている値の範囲の最大値です。要素に入力された {{htmlattrxref("value", "input")}} がこれを超えた場合、要素は制約検証に失敗します。 max 属性の値が数値でない場合、要素は最大値を持ちません。

+ +

この値は min 属性の値より大きいか、等しくしなければなりません。 HTML の max 属性を参照してください。

+ +

min

+ +

許可されている値の範囲の最小値です。要素の {{htmlattrxref("value", "input")}} がこれより小さい場合、要素は制約検証に失敗します。 min 属性の値が数値でない場合、要素は最小値を持ちません。

+ +

この値は min 属性の値より小さいか、等しくしなければなりません。 HTML の min 属性を参照してください。

+ +

step

+ +

{{page("/ja/docs/Web/HTML/Element/input/number", "step-include")}}

+ +

range 入力欄の既定の刻み値は 1 であり、刻みの基準値が整数ではない場合を除いて、整数の入力のみを許可します。例えば、 min に -10 を、 value に 1.5 を設定した場合、 step が 1 の場合は正の方向に 1.5, 2.5, 3.5,... など、負の方向に -0.5, -1.5, -2.5,... などのみが許可されます。 HTML の step 属性を参照してください。

+ +

標準外の属性

+ + + + + + + + + + + + + + +
属性説明
{{anch("orient")}}範囲のスライダーの向きを設定します。 Firefox のみ。
+ +

orient {{non-standard_inline}}

+ +

CSS の標準外の -moz-orient non-standard プロパティと同様に {{htmlelement('progress')}} および {{htmlelement('meter')}} 要素に影響を与える orient 属性は、範囲スライダーの向きを定義する定義します。値は horizontal が範囲を水平方向に描画することを、 vertical が範囲を垂直に描画することを意味します。

+ +
+

メモ: input 型の属性のうち、 accept, alt, checked, dirname, formaction, formenctype, formmethod, formnovalidate, formtarget, height, maxlength, minlength, multiple, pattern, placeholder, readonly, required, size, src, width は範囲入力には適用されません。これらの属性が含まれた場合は無視されます。

+
+ +

+ +

number 型がユーザーに数値を入力させ、任意で値を最小値と最大値の間に強制することができるものですので、具体的な値を入力する必要があります。 range 入力型は、どの値が選択されているかをユーザーが気にする、または知る必要がない場合に、ユーザーに値を尋ねることができます。

+ +

range 入力欄がよく使用される場合の例をいくつか示します。

+ + + +

原則として、ユーザーが実際の数値自体よりも最大値と最小値の間のパーセント値に関心がある場合は、 range 入力が最有力候補になります。例えば、ホームステレオの音量制御では、ユーザーは通常「音量を0.5に設定する」ではなく、「音量を最大値の半分くらいに設定する」と考えます。

+ +

最小値と最大値の指定

+ +

既定では、最小値は0で最大値は100です。これが望むものでないのであれば、 {{htmlattrxref("min", "input")}} や {{htmlattrxref("max", "input")}} 属性の値を変更することで、簡単に範囲を変更することができます。浮動小数点値にすることもできます。

+ +

例えば、ユーザーに -10 から 10 までの値を尋ねるのであれば、次のようにすることができます。

+ +
<input type="range" min="-10" max="10">
+ +

{{EmbedLiveSample("Specifying_the_minimum_and_maximum", 600, 40)}}

+ +

値の精度の設定

+ +

By default, the granularity, is 1, meaning that the value is always an integer. You can change the {{htmlattrxref("step")}} attribute to control the granularity. For example, If you need a value between 5 and 10, accurate to two decimal places, you should set the value of step to 0.01:

+ +
+
<input type="range" min="5" max="10" step="0.01">
+ +

{{EmbedLiveSample("Granularity_sample1", 600, 40)}}

+
+ +

If you want to accept any value regardless of how many decimal places it extends to, you can specify a value of any for the {{htmlattrxref("step", "input")}} attribute:

+ +
+
<input type="range" min="0" max="3.14" step="any">
+ +

{{EmbedLiveSample("Granularity_sample2", 600, 40)}}

+ +

This example lets the user select any value between 0 and π without any restriction on the fractional part of the value selected.

+
+ +

ハッシュマークとラベルの追加

+ +

The HTML specification gives browsers some flexibility on how to present the range control. Nowhere is this flexibility more apparent than in the area of hash marks and, to a lesser degree, labels. The specification describes how to add custom points to the range control using the {{htmlattrxref("list", "input")}} attribute and a {{HTMLElement("datalist")}} element, but does not have any requirements or even recommendations for standardized hash or tick marks along the length of the control.

+ +

範囲コントロールのモックアップ

+ +

Since browsers have this flexibility, and to date none support all of the features HTML defines for range controls, here are some mockups to show you what you might get on macOS in a browser which supports them.

+ +
簡素な範囲コントロール
+ +

This is what you get if you don't specify a {{htmlattrxref("list", "input")}} attribute, or if the browser doesn't support it.

+ + + + + + + + + + + + + + + + + + + + + +
HTMLExamples
+
+<input type="range">
+
Screenshot
Screenshot of a plain slider control on macOS
Live
{{EmbedLiveSample("An_unadorned_range_control",200,55,"","", "nobutton")}}
+ +
ハッシュマーク付きの範囲コントロール
+ +

This range control is using a list attribute specifying the ID of a {{HTMLElement("datalist")}} which defines a series of hash marks on the control. There are eleven of them, so that there's one at 0% as well as at each 10% mark. Each point is represented using an {{HTMLElement("option")}} element with its {{htmlattrxref("value", "option")}} set to the range's value at which a mark should be drawn.

+ + + + + + + + + + + + + + + + + + + + + +
HTMLExamples
+
+<input type="range" list="tickmarks">
+
+<datalist id="tickmarks">
+  <option value="0"></option>
+  <option value="10"></option>
+  <option value="20"></option>
+  <option value="30"></option>
+  <option value="40"></option>
+  <option value="50"></option>
+  <option value="60"></option>
+  <option value="70"></option>
+  <option value="80"></option>
+  <option value="90"></option>
+  <option value="100"></option>
+</datalist>
+
+
Screenshot
Screenshot of a plain slider control on macOS
Live
{{EmbedLiveSample("A_range_control_with_hash_marks_and_labels",200,55,"","", "nobutton")}}
+ +
ハッシュマークとラベル付きの範囲コントロール
+ +

You can add labels to your range control by adding the {{htmlattrxref("label", "option")}} attribute to the {{HTMLElement("option")}} elements corresponding to the tick marks you wish to have labels for.

+ + + + + + + + + + + + + + + + + + + + + +
HTMLExamples
+
+<input type="range" list="tickmarks">
+
+<datalist id="tickmarks">
+  <option value="0" label="0%"></option>
+  <option value="10"></option>
+  <option value="20"></option>
+  <option value="30"></option>
+  <option value="40"></option>
+  <option value="50" label="50%"></option>
+  <option value="60"></option>
+  <option value="70"></option>
+  <option value="80"></option>
+  <option value="90"></option>
+  <option value="100" label="100%"></option>
+</datalist>
+
+
Screenshot
Screenshot of a plain slider control on macOS
Live
{{EmbedLiveSample("A_range_control_with_hash_marks_and_labels",200,55,"","", "nobutton")}}
+ +
+

Note: Currently, no browser fully supports these features. Firefox doesn't support hash marks and labels at all, for example, while Chrome supports hash marks but doesn't support labels. Version 66 (66.0.3359.181) of Chrome supports labels but the {{htmlelement("datalist")}} tag has to be styled with CSS as its {{cssxref("display")}} property is set to none by default, hiding the labels.

+
+ +

方向の変更

+ +
+

By default, if a browser renders a range input as a slider, it will render it so that the knob slides left and right. When supported, we will be able to make the range vertical, to slide up and down with CSS by declaring a height value greater than the width value. This is not actually implemented yet by any of the major browsers. (See Firefox {{bug(981916)}}, Chrome bug 341071). It also, perhaps, may still be under discussion.

+ +

In the meantime, we can make the range vertical by rotating it using CSS transforms, or, by targeting each browser engine with their own method, which includes setting the {{cssxref('appearance')}} to slider-vertical, by using a non-standard orient attribute in Firefox, or by changing the text direction for Internet Explorer and Edge.

+ +

Consider this range control:

+ +
+
<input type="range" id="volume" min="0" max="11" value="7" step="1">
+
+ +

{{EmbedLiveSample("Orientation_sample1", 200, 200, "orientation_sample1.png")}}

+ +

This control is horizontal (at least on most if not all major browsers; others might vary).

+
+ +

Standards

+ +

According to the specification, making it vertical requires adding CSS to change the dimensions of the control so that it's taller than it is wide, like this:

+ +
+

CSS

+ +
#volume {
+  height: 150px;
+  width: 50px;
+}
+ +

HTML

+ +
<input type="range" id="volume" min="0" max="11" value="7" step="1">
+ +

結果

+ +

{{EmbedLiveSample("Orientation_sample2", 200, 200, "orientation_sample2.png")}}

+
+ +

Unfortunately, no major browsers currently support vertical range controls directly.

+ +

transform: rotate(-90deg)

+ +

You can, however, create a vertical range control by drawing a horizontal range control on its side. The easiest way is to use CSS: by applying a {{cssxref("transform")}} to rotate the element, you can make it vertical. Let's take a look.

+ +

HTML

+ +

The HTML needs to be updated to wrap the {{HTMLElement("input")}} in a {{HTMLElement("div")}} to let us correct the layout after the transform is performed (since transforms don't automatically affect the layout of the page):

+ +
<div class="slider-wrapper">
+  <input type="range" min="0" max="11" value="7" step="1">
+</div>
+ +

CSS

+ +

Now we need some CSS. First is the CSS for the wrapper itself; this specifies the display mode and size we want so that the page lays out correctly; in essence, it's reserving an area of the page for the slider so that the rotated slider fits into the reserved space without making a mess of things.

+ +
.slider-wrapper {
+  display: inline-block;
+  width: 20px;
+  height: 150px;
+  padding: 0;
+}
+
+ +

Then comes the style information for the <input> element within the reserved space:

+ +
.slider-wrapper input {
+  width: 150px;
+  height: 20px;
+  margin: 0;
+  transform-origin: 75px 75px;
+  transform: rotate(-90deg);
+}
+ +

The size of the control is set to be 150 pixels long by 20 pixels tall. The margins are set to 0 and the {{cssxref("transform-origin")}} is shifted to the middle of the space the slider rotates through; since the slider is configured to be 150 pixels wide, it rotates through a box which is 150 pixels on each side. Offsetting the origin by 75px on each axis means we will rotate around the center of that space. Finally, we rotate counter-clockwise by 90°. The result: a range input which is rotated so the maximum value is at the top and the minimum value is at the bottom.

+ +

{{EmbedLiveSample("transform_rotate-90deg", 200, 200, "orientation_sample3.png")}}

+ +

appearance property

+ +

The {{cssxref('appearance')}} property has a non-standard value of slider-vertical that, well, makes sliders vertical.

+ +

HTML

+ +

We use the same HTML as in the previous examples:

+ +
<input type="range" min="0" max="11" value="7" step="1">
+
+ +

CSS

+ +

We target just the inputs with a type of range:

+ +
input[type="range"] {
+  -webkit-appearance: slider-vertical;
+}
+ +

{{EmbedLiveSample("appearance_property", 200, 200)}}

+ +

orient attribute

+ +

In Firefox only, there is a non-standard orient property.

+ +

HTML

+ +

Use similar HTML as in the previous examples, we add the attribute with a value of vertical:

+ +
<input type="range" min="0" max="11" value="7" step="1" orient="vertical">
+
+ +

{{EmbedLiveSample("orient_attribute", 200, 200)}}

+ +

writing-mode: bt-lr;

+ +

The {{cssxref('writing-mode')}} property should generally not be used to alter text direction for internationalization or localization purposes, but can be used for special effects. 

+ +

HTML

+ +

We use the same HTML as in the previous examples:

+ +
<input type="range" min="0" max="11" value="7" step="1">
+
+ +

CSS

+ +

We target just the inputs with a type of range, changing the writing mode from the default to bt-lr, or bottom-to-top and left-to-right:

+ +
input[type="range"] {
+  writing-mode: bt-lr;
+}
+ +

{{EmbedLiveSample("writing-mode_bt-lr", 200, 200)}}

+ +

Putting it all together

+ +

As each of the above examples works in different browsers, you can put all of them in a single example to make it work cross browser:

+ +

HTML

+ +

We keep the orient attribute with a value of vertical for Firefox:

+ +
<input type="range" min="0" max="11" value="7" step="1" orient="vertical">
+
+ +

CSS

+ +

We target just the inputs with a type of range, changing the writing mode from the default to bt-lr, or bottom-to-top and left-to-right, for Edge and Internet Explorer, and add -webkit-appearance: slider-vertical for all -webkit-based browsers:

+ +
input[type="range"] {
+  writing-mode: bt-lr;
+  -webkit-appearance: slider-vertical;
+}
+ +

{{EmbedLiveSample("Putting_it_all_together", 200, 200)}}

+ +

仕様書

+ +

{{Specifications}}

+ +

ブラウザーの互換性

+ +

{{Compat}}

+ +

関連情報

+ + -- cgit v1.2.3-54-g00ecf