Skip to main content
Glama

get_computed_styles

Read-only

Retrieve computed CSS values for any element's properties, organized by layout, visibility, spacing, and typography categories.

Instructions

INSPECT CSS PROPERTIES: Get computed CSS values for specific properties (display, position, width, etc.). Use when you need raw CSS values or specific properties not shown by measure_element(). Returns styles grouped by category (Layout, Visibility, Spacing, Typography). For box model visualization (padding/margin), use measure_element() instead.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
selectorYesCSS selector, text selector, or testid shorthand (e.g., 'testid:submit-button', '#main')
propertiesNoComma-separated list of CSS properties to retrieve (e.g., 'display,width,color'). If not specified, returns common layout properties: display, position, width, height, opacity, visibility, z-index, overflow, margin, padding, font-size, font-weight, color, background-color

Implementation Reference

  • The execute() method that performs the tool logic: parses properties, selects the element via locator, evaluates computed CSS styles in the browser, groups them by category (Layout, Visibility, Spacing, Typography, Other), and returns the formatted text response.
      async execute(args: { selector: string; properties?: string }, context: ToolContext): Promise<ToolResponse> {
        return this.safeExecute(context, async (page) => {
          // Parse properties parameter
          const properties = args.properties
            ? args.properties.split(',').map(p => p.trim())
            : this.DEFAULT_PROPERTIES;
    
          // Use standard element selection with visibility preference
          const locator = await this.createScopedLocator(page, args.selector);
          const { element, elementIndex, totalCount } = await this.selectPreferredLocator(locator, {
            originalSelector: args.selector,
          });
    
          // Format selection warning if multiple elements matched
          const warning = await this.formatElementSelectionInfo(
            args.selector,
            elementIndex,
            totalCount
          );
    
          // Get element tag and selector info
          const elementInfo = await element.evaluate((el) => {
            const attrs: string[] = [];
            const tag = el.tagName.toLowerCase();
            if (el.id) attrs.push(`#${el.id}`);
            if (el.className && typeof el.className === 'string') {
              const classes = el.className.split(' ').filter(c => c).slice(0, 2);
              if (classes.length) attrs.push(`.${classes.join('.')}`);
            }
            const testId = el.getAttribute('data-testid') || el.getAttribute('data-test') || el.getAttribute('data-cy');
            if (testId) attrs.push(`data-testid="${testId}"`);
    
            return {
              tag,
              display: attrs.length ? `<${tag} ${attrs.join(' ')}>` : `<${tag}>`
            };
          });
    
          // Get computed styles
          const styles = await element.evaluate((el, props) => {
            const computed = window.getComputedStyle(el);
            const result: Record<string, string> = {};
            props.forEach((prop: string) => {
              result[prop] = computed.getPropertyValue(prop);
            });
            return result;
          }, properties);
    
          // Group styles by category
          const layout: string[] = [];
          const visibility: string[] = [];
          const spacing: string[] = [];
          const typography: string[] = [];
          const other: string[] = [];
    
          const layoutProps = ['display', 'position', 'width', 'height', 'top', 'left', 'right', 'bottom'];
          const visibilityProps = ['opacity', 'visibility', 'z-index', 'overflow', 'overflow-x', 'overflow-y'];
          const spacingProps = ['margin', 'margin-top', 'margin-right', 'margin-bottom', 'margin-left',
                                'padding', 'padding-top', 'padding-right', 'padding-bottom', 'padding-left'];
          const typographyProps = ['font-size', 'font-weight', 'font-family', 'color', 'line-height', 'text-align'];
    
          Object.entries(styles).forEach(([prop, value]) => {
            const line = `  ${prop}: ${value}`;
            if (layoutProps.includes(prop)) {
              layout.push(line);
            } else if (visibilityProps.includes(prop)) {
              visibility.push(line);
            } else if (spacingProps.includes(prop)) {
              spacing.push(line);
            } else if (typographyProps.includes(prop)) {
              typography.push(line);
            } else {
              other.push(line);
            }
          });
    
          // Build output
          const sections: string[] = [];
    
          if (warning) {
            sections.push(warning.trim());
          }
    
          sections.push(`Computed Styles: ${elementInfo.display}\n`);
    
          if (layout.length) {
            sections.push('Layout:\n' + layout.join('\n'));
          }
          if (visibility.length) {
            sections.push('Visibility:\n' + visibility.join('\n'));
          }
          if (spacing.length) {
            sections.push('Spacing:\n' + spacing.join('\n'));
          }
          if (typography.length) {
            sections.push('Typography:\n' + typography.join('\n'));
          }
          if (other.length) {
            sections.push('Other:\n' + other.join('\n'));
          }
    
          return {
            content: [
              {
                type: 'text',
                text: sections.join('\n\n')
              }
            ],
            isError: false
          };
        });
      }
    }
  • Input schema for the tool: accepts 'selector' (required string) and 'properties' (optional comma-separated string of CSS properties).
        inputSchema: {
          type: "object",
          properties: {
            selector: {
              type: "string",
              description: "CSS selector, text selector, or testid shorthand (e.g., 'testid:submit-button', '#main')"
            },
            properties: {
              type: "string",
              description: "Comma-separated list of CSS properties to retrieve (e.g., 'display,width,color'). If not specified, returns common layout properties: display, position, width, height, opacity, visibility, z-index, overflow, margin, padding, font-size, font-weight, color, background-color"
            }
          },
          required: ["selector"],
        },
      };
    }
  • Tool registration: GetComputedStylesTool is listed in the BROWSER_TOOL_CLASSES array (line 88) which registers it as an available browser tool.
    export const BROWSER_TOOL_CLASSES: ToolClass[] = [
      // Navigation (5)
      NavigateTool,
      GoHistoryTool,
      ScrollToElementTool,
      ScrollByTool,
    
      // Lifecycle (2)
      CloseTool,
      SetColorSchemeTool,
    
      // Interaction (7)
      ClickTool,
      FillTool,
      SelectTool,
      HoverTool,
      UploadFileTool,
      DragTool,
      PressKeyTool,
    
      // Content (3)
      ScreenshotTool,
      GetTextTool,
      GetHtmlTool,
    
      // Inspection (10)
      InspectDomTool,
      GetTestIdsTool,
      QuerySelectorTool,
      FindByTextTool,
      CheckVisibilityTool,
      CompareElementAlignmentTool,
      InspectAncestorsTool,
      ElementExistsTool,
      MeasureElementTool,
      GetComputedStylesTool,
    
      // Evaluation (1)
      EvaluateTool,
    
      // Console (2)
      GetConsoleLogsTool,
      ClearConsoleLogsTool,
    
      // Network (2)
      ListNetworkRequestsTool,
      GetRequestDetailsTool,
    
      // Waiting (2)
      WaitForElementTool,
      WaitForNetworkIdleTool,
    ];
  • Import statement that brings GetComputedStylesTool into the registration module.
    import { GetComputedStylesTool } from './inspection/get_computed_styles.js';
  • Default list of CSS properties used when the user does not specify custom properties.
    private readonly DEFAULT_PROPERTIES = [
      'display', 'position', 'width', 'height',
      'opacity', 'visibility', 'z-index', 'overflow',
      'margin', 'padding',
      'font-size', 'font-weight', 'color', 'background-color'
    ];
Behavior5/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

Annotations confirm readOnlyHint=true. Description adds context that results are grouped by category (Layout, Visibility, Spacing, Typography), which informs the agent about output structure. No contradictions.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Four sentences, all essential. First sentence is an imperative summary, followed by usage guidance and alternative. No wasted words.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness5/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Two required parameters fully described in schema. No output schema, but description mentions grouping categories. All relevant context for selection and invocation is present.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema coverage is 100% with parameter descriptions. Tool description adds the default properties list (e.g., 'display,width,height,...') beyond the schema's shorter description, providing extra clarity.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

Description starts with a strong, specific 'INSPECT CSS PROPERTIES' and clearly defines the action: 'Get computed CSS values for specific properties'. It identifies the resource (CSS properties of an element) and distinguishes from sibling 'measure_element()'.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines5/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

Explicitly states when to use ('when you need raw CSS values or specific properties not shown by measure_element()') and when not to ('For box model visualization... use measure_element() instead'), providing clear guidance.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/antonzherdev/mcp-web-inspector'

If you have feedback or need assistance with the MCP directory API, please join our Discord server