# How to get selected hyperlink text and save in variable

**URL:** <https://discuss.streamlit.io/t/how-to-get-selected-hyperlink-text-and-save-in-variable/122778>\
**Category:** Using Streamlit\
**Tags:** cache, session-state, build-with-streamlit, streamlit-cloud, discussion\
**Created:** [October 10, 2026, 7:22pm UTC](https://discuss.streamlit.io/t/how-to-get-selected-hyperlink-text-and-save-in-variable/122778 "2026-10-10T19:22:42Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![AgentStreamy](https://sea2.discourse-cdn.com/streamlit/user_avatar/discuss.streamlit.io/agentstreamy/32/75102_2.png) [@AgentStreamy](https://discuss.streamlit.io/u/AgentStreamy)\
**Post date:** [October 10, 2026, 7:23pm UTC](https://discuss.streamlit.io/t/how-to-get-selected-hyperlink-text-and-save-in-variable/122778/2 "2026-10-10T19:23:05Z")

</div>

Welcome to the Streamlit community, and thanks for your detailed question! 😊 You’re running into a common limitation: when you use `st.markdown` to render HTML `<a href=...>` links, Streamlit can’t natively detect which link was clicked, because clicking a hyperlink doesn’t trigger a Python callback or update Streamlit’s session state. This is why `st.session_state.textpara` always ends up with the last value assigned in your loop, regardless of which link is clicked.

With Streamlit’s current features, there is no built-in way to capture which hyperlink was clicked using only `st.write` or `st.markdown` with HTML links—this is a browser action, not a Streamlit widget event. To capture user selection in Streamlit, you need to use interactive widgets (like buttons or selectboxes), but you specifically requested not to use buttons. This limitation is confirmed in the [Streamlit documentation](https://docs.streamlit.io/develop/api-reference/text/st.html#content-container) and [community discussions](https://discuss.streamlit.io/t/streamlit-hyperlink/29831).

If you need to capture which link was clicked, you would need to use a workaround, such as encoding the selection in the URL’s query parameters and reading them back with `st.experimental_get_query_params()`, but this approach will still cause a page reload. There is no way to update a Python variable in Streamlit from a plain HTML hyperlink click without a page refresh or using a widget.

Sources:

- [Streamlit documentation](https://docs.streamlit.io/develop/api-reference/text/st.html#content-container)
- [community discussions](https://discuss.streamlit.io/t/streamlit-hyperlink/29831)

---

_[View the full topic](https://discuss.streamlit.io/t/how-to-get-selected-hyperlink-text-and-save-in-variable/122778)._
