# ui.status_code | NiceGUI

[Button: icon:menu]

[](/)

[Installation](/#installation)

[Features](/#features)

[Demos](/#demos)

[Documentation](/documentation)

[Examples](/examples)

[Why?](/#why)

[Button]

[Button]

[](https://github.com/zauberzeug/nicegui/)

[Button: icon:more_vert]

# ui.*status_code*

## Status code

Set the HTTP status code for the current page response.
Must be called during page building, before the response is sent to the client.

*Added in version 3.10.0*

:code: HTTP status code (e.g. 200, 404, 503)

main.py

[Button]

````python
from nicegui import ui

@ui.page('/teapot')
def teapot_page():
    ui.status_code(418)
    ui.label("I'm a teapot")

@ui.page('/')
def page():
    ui.link('Visit the teapot page', '/teapot')

ui.run()
````

## Conditional 404

You can use `ui.status_code` to return a 404 status code when an item is not found.
This is useful for SEO and for signaling to clients that a page does not exist.

main.py

[Button]

````python
from nicegui import ui

@ui.page('/item/{item_id}')
def item_page(item_id: str):
    if 'a' <= item_id <= 'c':
        ui.label(f'This is item {item_id}')
    else:
        ui.status_code(404)
        ui.label('Page not found')

@ui.page('/')
def page():
    ui.link('Show item A', '/item/a')
    ui.link('Show item B', '/item/b')
    ui.link('Show item X', '/item/x')

ui.run()
````

**Nice**GUI

The Python UI framework that shows up in your browser.

[](https://github.com/zauberzeug/nicegui/)

[](https://discord.gg/TEpFeAaF4f)

[](https://www.reddit.com/r/nicegui/)

Resources

[Documentation](/documentation)

[Examples](/examples)

[LLM reference](/llms.txt)

[GitHub](https://github.com/zauberzeug/nicegui/)

[PyPI](https://pypi.org/project/nicegui/)

Community

[Discussions](https://github.com/zauberzeug/nicegui/discussions)

[Discord](https://discord.gg/TEpFeAaF4f)

[Reddit](https://www.reddit.com/r/nicegui/)

[Contributing](https://github.com/zauberzeug/nicegui/blob/main/CONTRIBUTING.md)

[Sponsors](https://github.com/sponsors/zauberzeug)

Legal

[Imprint](/imprint_privacy#imprint)

[Privacy](/imprint_privacy#privacy)

Made with NiceGUI by [Zauberzeug](https://zauberzeug.com)

© 2026 [Zauberzeug GmbH](https://zauberzeug.com)