From c395bb07a6b003e6cfe9f14c8e11c86d575dcee8 Mon Sep 17 00:00:00 2001
From: Masahiro FUJIMOTO {{HTMLElement("input")}} 要素の ユーザーのブラウザーが 利用可能なパターン検証はありません。しかし、以下の形で自動検証が行われます。 {{htmlattrxref("value", "input")}} 属性は、選択された数値を表す文字列が入った {{domxref("DOMString")}} です。値は空文字列 ( 最小値よりも小さな値を設定しようとすると、最小値に設定されます。同様に、最大値よりも大きな値を設定しようとすると、最大値に設定される結果になります。 すべての {{HTMLElement("input")}} 型で共通する属性に加え、 {{page("/ja/docs/Web/HTML/Element/input/text", "attr-list", 0, 1, 2)}} 対応しているブラウザーで、範囲のオプションがどのように表示されるかの例としては、以下のハッシュマーク付き範囲コントロールを参照してください。 許可されている値の範囲の最大値です。要素に入力された {{htmlattrxref("value", "input")}} がこれを超えた場合、要素は制約検証に失敗します。 この値は 許可されている値の範囲の最小値です。要素の {{htmlattrxref("value", "input")}} がこれより小さい場合、要素は制約検証に失敗します。 この値は {{page("/ja/docs/Web/HTML/Element/input/number", "step-include")}} CSS の標準外の -moz-orient non-standard プロパティと同様に {{htmlelement('progress')}} および {{htmlelement('meter')}} 要素に影響を与える メモ: input 型の属性のうち、 range 入力欄がよく使用される場合の例をいくつか示します。 原則として、ユーザーが実際の数値自体よりも最大値と最小値の間のパーセント値に関心がある場合は、 range 入力が最有力候補になります。例えば、ホームステレオの音量制御では、ユーザーは通常「音量を0.5に設定する」ではなく、「音量を最大値の半分くらいに設定する」と考えます。range 型は、ユーザーに特定の値より小さくなく、別な特定の値より大きくない数値を指定させるために使用します。しかし、厳密な値が重要であるとはされません。これは通常、 {{HTMLElement('input/number', 'number')}} 入力型のようなテキスト入力ボックスではなく、スライダーやダイアルコントロールを用いて表現されます。この種のウィジェットは厳密なものではないので、コントロールの正確な値が重要でない限り、通常は使用するべきではありません。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()")}}
-
+
+ {{anch("値")}}
+
+ 選択された数値を表す文字列を含む {{domxref("DOMString")}}。数値として値を取得するには {{domxref("HTMLInputElement.valueAsNumber", "valueAsNumber")}} を使用してください。
+
+
+
+ イベント
+
+ {{domxref("HTMLElement/change_event", "change")}} および
+ {{domxref("HTMLElement/input_event", "input")}}
+
+
+
+ 対応している共通属性
+
+ {{htmlattrxref("autocomplete", "input")}},
+ {{htmlattrxref("list", "input")}},
+ {{htmlattrxref("max", "input")}},
+ {{htmlattrxref("min", "input")}},
+ {{htmlattrxref("step", "input")}}
+
+
+
+ IDL 属性
+
+ list, value, valueAsNumber
+
+
メソッド
+
+ {{domxref("HTMLInputElement.stepUp", "stepUp()")}},
+ {{domxref("HTMLInputElement.stepDown", "stepDown()")}}
+
+ 検証
-
-
-
-
-値
-
-"") にはなりません。既定値は指定された最大値と最小値の中間値で、ただし最大値が最小値を下回っている場合は、既定値は min 属性の値に設定されます。既定値を特定するアルゴリズムは次の通りです。defaultValue = (rangeElem.max < rangeElem.min) ? rangeElem.min
- : rangeElem.min + (rangeElem.max - rangeElem.min)/2;
-
-追加の属性
-
-range 型の入力欄は次の属性にも対応しています。
-
-
+### 検証
-
-
-
-
- 属性
- 説明
-
-
-
- {{anch("list")}}オプションで自動補完の定義済みの選択肢を含む <datalist> 要素の id
-
-
-
- {{anch("max")}}許可されている最大値
-
-
-
- {{anch("min")}}許可されている最小値
-
-
-
-
- {{anch("step")}}ユーザーインターフェイスと検証の両方で使用される刻み値
-
+### 値
-maxmax 属性の値が数値でない場合、要素は最大値を持ちません。min 属性の値より大きいか、等しくしなければなりません。 HTML の max 属性を参照してください。
+最小値よりも小さな値を設定しようとすると、最小値に設定されます。同様に、最大値よりも大きな値を設定しようとすると、最大値に設定される結果になります。
-minmin 属性の値が数値でない場合、要素は最小値を持ちません。min 属性の値より小さいか、等しくしなければなりません。 HTML の min 属性を参照してください。
+### list
-steprange 入力欄の既定の刻み値は 1 であり、刻みの基準値が整数ではない場合を除いて、整数の入力のみを許可します。例えば、 min に -10 を、 value に 1.5 を設定した場合、 step が 1 の場合は正の方向に 1.5, 2.5, 3.5,... など、負の方向に -0.5, -1.5, -2.5,... などのみが許可されます。 HTML の step 属性を参照してください。標準外の属性
+### max
-
-
-
+この入力欄が受け付ける最大値です。要素に入力された {{htmlattrxref("value", "input")}} がこれを超えた場合、要素は[制約検証](/ja/docs/Web/Guide/HTML/Constraint_validation)に失敗します。 [`max`](/ja/docs/Web/HTML/Attributes/max) 属性の値が数値でない場合、要素は最大値を持ちません。
-
-
-
-
- 属性
- 説明
-
-
-
-
- {{anch("orient")}}範囲のスライダーの向きを設定します。 Firefox のみ。
-
+この値は [`min`](/ja/docs/Web/HTML/Attributes/min) 属性の値より大きいか、等しくしなければなりません。HTML の [`max`](/ja/docs/Web/HTML/Attributes/max) 属性を参照してください。
-orient {{non-standard_inline}}orient 属性は、範囲スライダーの向きを定義する定義します。値は horizontal が範囲を水平方向に描画することを、 vertical が範囲を垂直に描画することを意味します。accept, alt, checked, dirname, formaction, formenctype, formmethod, formnovalidate, formtarget, height, maxlength, minlength, multiple, pattern, placeholder, readonly, required, size, src, width は範囲入力には適用されません。これらの属性が含まれた場合は無視されます。例
+この値は [`max`](/ja/docs/Web/HTML/Attributes/max) 属性の値以下でなければなりません。 HTML の [`min`](/ja/docs/Web/HTML/Attributes/min) 属性を参照してください。
-number 型がユーザーに数値を入力させ、任意で値を最小値と最大値の間に強制することができるものですので、具体的な値を入力する必要があります。 range 入力型は、どの値が選択されているかをユーザーが気にする、または知る必要がない場合に、ユーザーに値を尋ねることができます。
-
+文字列値の `any` は、刻みがなく、どの値でも許可されることを意味します(`{{anch("min")}}` や `{{anch("max")}}` など、他の制約には制限されます)。
-最小値と最大値の指定
+`range` 入力欄の既定の刻み値は 1 であり、刻みの基準値が整数ではない場合を*除いて*、整数の入力のみを許可します。例えば、 `min` に -10 を、 `value` に 1.5 を設定した場合、 `step` が 1 の場合は正の方向に 1.5, 2.5, 3.5,... など、負の方向に -0.5, -1.5, -2.5,... などのみが許可されます。 [HTML の `step` 属性](/ja/docs/Web/HTML/Attributes/step)を参照してください。
既定では、最小値は0で最大値は100です。これが望むものでないのであれば、 {{htmlattrxref("min", "input")}} や {{htmlattrxref("max", "input")}} 属性の値を変更することで、簡単に範囲を変更することができます。浮動小数点値にすることもできます。
+### 標準外の属性 -例えば、ユーザーに -10 から 10 までの値を尋ねるのであれば、次のようにすることができます。
+### orient -<input type="range" min="-10" max="10">+CSS の標準外の -moz-orient non-standard プロパティと同様に {{htmlelement('progress')}} および {{htmlelement('meter')}} 要素に影響を与える `orient` 属性は、範囲スライダーの向きを定義する定義します。値は `horizontal` が範囲を水平方向に描画することを、 `vertical` が範囲を垂直に描画することを意味します。 -
{{EmbedLiveSample("Specifying_the_minimum_and_maximum", 600, 40)}}
+> **Note:** input 型の属性のうち、 `accept`, `alt`, `checked`, `dirname`, `formaction`, `formenctype`, `formmethod`, `formnovalidate`, `formtarget`, `height`, `maxlength`, `minlength`, `multiple`, `pattern`, `placeholder`, `readonly`, `required`, `size`, `src`, `width` は範囲入力には適用されません。これらの属性が含まれた場合は無視されます。 -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">+range 入力欄がよく使用される場合の例をいくつか示します。 -
{{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)}}
+既定では、最小値は 0 で最大値は 100 です。これが望むものでないのであれば、 {{htmlattrxref("min", "input")}} や {{htmlattrxref("max", "input")}} 属性の値を変更することで、簡単に範囲を変更することができます。浮動小数点値にすることもできます。 -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.
+{{EmbedLiveSample("Setting_step_to_any", 600, 40)}} -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.
+#### 範囲コントロールのモックアップ + +ブラウザーにはこのような柔軟性がありますが、 HTML が定義する範囲コントロールの機能すべてに対応しているものは今のところありません。ここでは、それらに対応しているブラウザーで、 macOS で得られるかもしれないものを示すモックアップをいくつか紹介します。 + +##### 簡素な範囲コントロール + +これは {{htmlattrxref("list", "input")}} 属性を指定しない場合や、ブラウザーが対応していない場合に表示されるものです。| HTML | -Examples | -
|---|---|
- -<input type="range">- |
- Screenshot | -
![]() |
- |
| Live | -|
| {{EmbedLiveSample("An_unadorned_range_control",200,55,"","", "nobutton")}} | -|
| HTML | +例 | +
+ <input type="range">+ |
+ 画面ショット | +
+
+ |
+ |
| ライブ | +|
| + {{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.
| HTML | -Examples | -
|---|---|
- -<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 | -
![]() |
- |
| Live | -|
| {{EmbedLiveSample("A_range_control_with_hash_marks_and_labels",200,55,"","", "nobutton")}} | -|
| HTML | +例 | +
+ +<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> + ++ |
+ 画面ショット | +
+
+ |
+ |
| ライブ | +|
| + {{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.
+ラベルを付けたい目盛りに対応する {{HTMLElement("option")}} 要素に {{htmlattrxref("label", "option")}} 属性を追加することにより、範囲コントロールにラベルを追加することができます。| HTML | -Examples | -
|---|---|
- -<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 | -
![]() |
- |
| Live | -|
| {{EmbedLiveSample("A_range_control_with_hash_marks_and_labels",200,55,"","", "nobutton")}} | -|
| HTML | +例 | +
+ +<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> + ++ |
+ 画面ショット | +
+
+ |
+ |
| ライブ | +|
| + {{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.
+既定では、ブラウザーが範囲入力をスライダーとしてレンダリングする場合、つまみが左右にスライドするようにレンダリングされます。対応すれば、 CSS で幅の値より大きい高さの値を宣言することで、範囲を垂直にして上下にスライドさせることができるようになります。これは、実はまだ主要なブラウザーでは実装されていません。(Firefox {{bug(981916)}}, [Chrome bug 341071](https://bugs.chromium.org/p/chromium/issues/detail?id=341071) 参照)。また、おそらく、まだ[議論中](https://github.com/whatwg/html/issues/4177)であるかもしれません。 -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")}}
+```html + +``` -This control is horizontal (at least on most if not all major browsers; others might vary).
-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:
+#### 標準ベースの垂直範囲コントロール -#volume {
+```css
+#volume {
height: 150px;
width: 50px;
-}
-
-<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.
+```html + +``` -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.
+残念ながら、現在垂直範囲コントロールに直接対応している主要なブラウザーはありません。 -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):
+水平方向の範囲コントロールを横に描画することで、垂直方向の範囲コントロールを作成することができます。最も簡単な方法は CSS を使うことです。 {{cssxref("transform")}} を適用して要素を回転させることで、縦長にすることができます。それでは見てみましょう。 -<div class="slider-wrapper"> - <input type="range" min="0" max="11" value="7" step="1"> -</div>+HTML を更新して {{HTMLElement("input")}} を {{HTMLElement("div")}} で囲み、座標変換が行われた後にレイアウトを修正できるようにします(座標変換は自動的にはページのレイアウトに影響しないので)。 -
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.
+次に、 CSS が必要です。これはページが正しく表示されるように、表示モードとサイズを指定します。要するに、スライダーのためにページの領域を確保し、回転したスライダーが混乱することなく確保したスペースに収まるようにします。 -.slider-wrapper {
+```css
+.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 {
+```css
+.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")}}
+} +``` -The {{cssxref('appearance')}} property has a non-standard value of slider-vertical that, well, makes sliders vertical.
We use the same HTML as in the previous examples:
+{{cssxref('appearance')}} プロパティには `slider-vertical` という標準外の値があり、スライダーを縦にします。 -<input type="range" min="0" max="11" value="7" step="1"> -+これまでの例と同じ HTML を使用します。 -
We target just the inputs with a type of range:
+`range` 型の入力だけを対象にします。 -input[type="range"] {
+```css
+input[type="range"] {
-webkit-appearance: slider-vertical;
-}
-
-{{EmbedLiveSample("appearance_property", 200, 200)}}
- -In Firefox only, there is a non-standard orient property.
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"> -+Firefox だけですが、標準外の `orient` プロパティがあります。 -
{{EmbedLiveSample("orient_attribute", 200, 200)}}
+前述の例と同様の HTML を使用しますが、この属性に `vertical` の値を設定します。 -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.
+{{EmbedLiveSample("Using_the_orient_attribute", 200, 200)}} -We use the same HTML as in the previous examples:
+{{cssxref('writing-mode')}} プロパティは、一般に国際化や地域化のためにテキスト方向を変更するために使用するべきではありませんが、特殊効果のために使うことができます。 -<input type="range" min="0" max="11" value="7" step="1"> -+前述の例と同様の HTML を使用します。 -
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"] {
+```css
+input[type="range"] {
writing-mode: bt-lr;
-}
-
-{{EmbedLiveSample("writing-mode_bt-lr", 200, 200)}}
- -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:
+{{EmbedLiveSample("writing-mode_bt-lr", 200, 200)}} -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"> -+`orient` 属性に `vertical` の値を設定することで Firefox に対応します。 -
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"] {
+```css
+input[type="range"] {
writing-mode: bt-lr;
-webkit-appearance: slider-vertical;
-}
+}
+```
-{{EmbedLiveSample("Putting_it_all_together", 200, 200)}}
+{{EmbedLiveSample("Putting_it_all_together", 200, 200)}} -{{Specifications}}
+{{Specifications}} -{{Compat}}
+{{Compat}} -<input type="number">