Skip to main content

Use Redoc in HTML

To render API documentation in an HTML page, start with the template below and replace the spec-url value with the local file path or URL of your API description. Open the HTML file in your browser to see the HTML documentation rendering.

Configure Redoc

Redoc is highly configurable, find a full list of configuration options on the dedicated page. To configure Redoc in HTML, add the property names to the HTML tag:
<redoc 
  spec-url='http://petstore.swagger.io/v2/swagger.json' 
  required-props-first=true
></redoc>

Theme configuration

For theme configuration, supply options as a JSON string:
<redoc 
  spec-url='http://petstore.swagger.io/v2/swagger.json'
  required-props-first=true
  theme='{
    "sidebar": {
      "backgroundColor": "lightblue"
    }
  }'
></redoc>
Check out the list of options for theme configuration for more customization options.

Advanced options

The Redoc object

The Redoc object offers an init function:
Redoc.init(specOrSpecUrl, options, element, callback)
Parameters:
  • specOrSpecUrl: JSON object with OpenAPI definition or file name/URL
  • options: See the configuration reference
  • element: Target DOM element
  • callback(optional): Called after rendering or on error
Example implementation:

Self-host dependencies

<script src="https://cdn.redoc.ly/redoc/latest/bundles/redoc.standalone.js"> </script>