Get to know MDN better
このページはコミュニティーの尽力で英語から翻訳されました。MDN Web Docs コミュニティーについてもっと知り、仲間になるにはこちらから。
This feature is not Baseline because it does not work in some of the most widely-used browsers.
Experimental: これは実験的な機能です。
本番で使用する前にブラウザー互換性一覧表をチェックしてください。
CSSFunctionRule は CSS オブジェクトモデルのインターフェイスで、CSS の @function(カスタム関数)アットルールを表します。
CSSRule CSSGroupingRule CSSFunctionRuleこのインターフェイスには CSSGroupingRule から継承したプロパティがあります。
CSSFunctionRule.name 読取専用このカスタム関数の名前を表す文字列を返します。
CSSFunctionRule.returnType 読取専用このカスタム関数の返値の型を表す文字列を返します。
このインターフェイスには CSSGroupingRule から継承したメソッドがあります。
CSSFunctionRule.getParameters()このカスタム関数の引数を表すオブジェクトの配列を返します。
この例では、CSS カスタム関数を定義し、CSSOM を使用してアクセスします。
この CSS では、@function アットルールを使用してカスタム関数を定義しています。この関数は --lighter() と呼ばれ、入力された色の明るさを調整した結果を返します。--lighter() は <color> と <number> の 2 つの引数を受け入れます。この関数は、相対色構文を使用して作成された oklch() 色を返します。入力された色は oklch() 色に変換され、その明度チャンネルが入力された数値分だけ増加されます。
このスクリプトはまず、HTMLStyleElement.sheet を使用して文書に添付されたスタイルシートへの参照を取得し、次に CSSStylesheet.cssRules を通じてスタイルシート内の唯一のルールである CSSFunctionRule への参照を取得します。その後、CSSFunctionRule のそれぞれのメンバーをコンソールにログ出力します。
name プロパティは --lighter となります。
returnType プロパティは <color> となります。
getParameters() メソッドは次のような配列を返します。
| CSS Functions and Mixins Module # the-function-interface |
Enable JavaScript to view this browser compatibility table.
This page was last modified on 2026年2月5日 by MDN contributors.
Your blueprint for a better internet.
Visit Mozilla Corporation’s not-for-profit parent, the Mozilla Foundation.
Portions of this content are ©1998–2026 by individual mozilla.org contributors. Content available under a Creative Commons license.